-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path109.c
69 lines (66 loc) · 1.32 KB
/
109.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<stdio.h>
typedef void(* pf_t)(int);//把void(*)(int)类型重命名 为pf_t
void menu()
{
printf("1,+.2-,3*,4/,0exit");
}
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;
}
int main()
{
void (*signal(int,void(*)(int)))(int );
pf_t signal(int,pf_t);
//函数指针的用途
//写一个计算器,加减乘除
int input = 0;
int x =0;
int y =0;
int ret = 0;
do {
menu();
printf("plz choose:\n");
scanf("%d",&input);
printf("plz input two number:\n");
scanf("%d %d",&x,&y);
switch(input)
{
case 1:
ret = Add(x,y);
printf("%d\n",ret);
break;
case 2:
ret = Sub(x,y);
printf("%d\n",ret);
break;
case 3:
ret =Mul(x,y);
printf("%d\n",ret);
break;
case 4:
ret = Div(x,y);
printf("%d\n",ret);
break;
case 0:
printf("exit\n");
break;
default:
printf("404");
break;
}
}while(input);
return 0;
}