-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfparr.c
72 lines (59 loc) · 977 Bytes
/
fparr.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
70
71
72
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
void menu()
{
printf("***********************\n");
printf("** 1.加法 2.减法 **\n");
printf("** 3.乘法 4.除法 **\n");
printf("** 5.异或 6.退出 **\n");
printf("***********************\n");
}
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 Xor(int x, int y)
{
return x ^ y;
}
int main()
{
int input = 0;
int x = 0;
int y = 0;
int(*pfArr[])(int, int) = { 0, Add, Sub, Mul, Div, Xor };
do
{
menu();
printf("请输入:>");
scanf("%d", &input);
if (input >= 1 && input <= 5)
{
printf("请输入两个操作数:>");
scanf("%d%d", &x, &y);
int ret = pfArr[input](x, y);
printf("%d\n", ret);
}
else if (input == 0)
{
printf("退出\n");
}
else
{
printf("输入错误,请重新输入\n");
}
} while (input);
return 0;
}