C语言高级专题(函数指针实战)
#include <stdio.h>
typedef int (*pFunc)(int ,int)
int main(void)
{
pFunc p1 = NULL;
char c = 0;
printf("请输入要操作的两个整数\n");
scanf("%d %d",&a,&b);
printf("请输操作类型:+ |-|*|/\n");
scanf("%c",&c);
int a=0,b=0,result=0;
switch (c)
{
case '+':
p1=add; break;
case '-':
p1=sub; break;
case'*':
p1=multiply; break;
case '/':
p1=divide; break;
default:
p1=NULL; break;
}
result =p1(a,b);
printf("%d %c %d =%d.\",a,c,b,result)
}
|