함수포인터 사용하지않고 다른거 사용해서 같은내용만드는것좀 도와주세요 ㅠ
팬지
질문 제목 : 질문 내용 : #includestdio.h
void menu(void);
int add(int x, int y);
int sub(int x, int y);
int mul(int x, int y);
int div(int x, int y);
void menu(void)
{
printf(==============\n);
printf(0, 덧셈\n);
printf(1, 뺄셈\n);
printf(2, 곱셈\n);
printf(3, 나눗셈\n);
printf(4, 종료\n);
printf(==============\n);
}
int main(void)
{
int choice, result, x, y;
//함수 포인터 배열을 선언하고 초기화한다.
int (*pf[4])(int, int) = { add, sub, mul, div };
while(1)
{
menu();
printf(메뉴를 선택하시오: );
scanf(%d, &choice);
if( choice 0 || choice =4 )
break;
printf(2개의 정수를 입력하시오: );
scanf(%d %d, &x, &y);
result = pf[choice](x, y);
printf(연산 결과 = %d\n, result );
}
return 0;
}
int add(int x, int y)
{
return x + y;
}
int sub(int x, int y)
{
return x - y;
}
int mul(int x, int y)
{
return x * y;
}
int div(int x, int y)
{
return x / y;
}
여기서 함수 포인터사용하지않고 다른거사용해서 똑같은내용나오게 하는건데요 도저히 못하겠어요 ㅠㅠ 도와주세용 ㅠ
-
앤드류
switch문이나 if else 문 사용하면 됩니다...