[[1번]]
#include <stdio.h>
void tri(int height, char prn);
void squ(int height, char prn);
int main()
{
int sel, height;
char prn;
printf("1.삼각형\n\n2.사각형\n");
printf("\n\n출력할 모양을 선택 : ");
scanf("%d", &sel);
fflush(stdin);
do
{
printf("높이 입력(2-30사이홀수) : ");
scanf("%d", &height);
fflush(stdin);
if(height <=2 || height >=30 || height%2 == 0)
{
printf("2와30사이의 홀수만 입력하세요\n");
continue;
}
else
{
printf("출력할 문자 : ");
prn = getchar();
fflush(stdin);
break;
}
}while(1);
switch(sel)
{
case 1:
printf("삼각형입니다\n");
tri(height, prn);
break;
case 2:
printf("사각형입니다\n");
squ(height, prn);
break;
}
return 0;
}
void tri(int height, char prn)
{
int i, j;
for(i=0; i<height; i++)
{
for(j=0; j<=i; j++)
{
printf("%c", prn);
}
printf("\n");
}
}
void squ(int height, char prn)
{
int i, j;
for(i=0; i<height; i++)
{
for(j=0; j<height-1; j++)
{
printf("%c", prn);
}
printf("%c", prn);
printf("\n");
}
}
[[2번]]
#include <stdio.h>
int absol(int a);
double xy(double x, double y);
int main()
{
int ab, x, y;
printf("절대값을 구할 정수 입력 : ");
scanf("%d", &ab);
fflush(stdin);
printf("|%d| = %d\n\n", ab, absol(ab));
printf("x^y를 구할 정수 입력\n");
printf("x : ");
scanf("%d", &x);
printf("y : ");
scanf("%d", &y);
printf("%d^%d = %.2f\n", x,y, xy(x, y));
return 0;
}
int absol(int a)
{
if(a < 0)
{
a = a*-1;
}
return a;
}
double xy(double x, double y)
{
int i;
double a;
a = x;
for(i=0; i<y-1; i++)
{
x *= a;
}
return x;
}