1 #include "stdio.h"
2 void main()
3 {
4 /*定义变量,d1,d2:第一、二个数 fu:符号 p1:接收判断号Y/N
5 p2:接收的p1赋给p1
6 */
7 int d1,d2;
8 char fu,p1,p2;
9 do
10 {
11 printf("请输入第一个数:");
12 scanf("%d",&d1); //接收数字
13 fflush(stdin); //清除缓存
14 printf("请输入一个运算符:");
15 scanf("%c",&fu); //接收运算符
16 fflush(stdin);
17 printf("请输入第二个数:");
18 scanf("%d",&d2);
19 fflush(stdin);//很容易漏掉,没有这个会使后面的判断Y/N接受不到
20 switch(fu)
21 {
22 case '+':printf("%d+%d=%d\n",d1,d2,d1+d2);break;
23 case '-':printf("%d-%d=%d\n",d1,d2,d1-d2);break;
24 case '*':printf("%d*%d=%d\n",d1,d2,d1*d2);break;
25 case '/':printf("%d/%d=%d\n",d1,d2,d1/d2);break;
26 case '%':printf("%d%%%d=%d\n",d1,d2,d1%d2);break;
27 default:printf("输入有误!");
28 }
29 printf("你是否需要继续计算(继续:Y,退出:N)");
30 scanf("%c",&p1); //接收判断句Y/N
31 fflush(stdin);
32 p2=p1;
33 if(p2=='N') //判断是否需要重复运算
34 {
35 break;
36 }
37
38 }while(1);
39 printf("程序结束!");
40
41
42
43 }
![]()