#include <stdio.h>
float sum(int a, int b) {
return a+b;
}
float jian(int a, int b) {
return a-b;
}
float cheng(int a, int b) {
return a*b;
}
float chu(int a, int b) {
return a*b;
}
int main(int argc, const char * argv[]) {
int a, b;
int n;
printf("请输入两个数:");
scanf("%d%d",&a, &b);
printf("请选择1.+ 2.- 3.* 4./ :");
scanf("%d", &n);
float (*p)(int,int);
switch (n) {
case 1:
p = sum;
break;
case 2:
p = jian;
break;
case 3:
p = cheng;
break;
case 4 :
p = chu;
break;
default:
printf("输入错误");
}
printf("结果是 %.2f\n", p(a, b));
return 0;
}
论坛爆炸,手机发见谅 |
|