四则运算

代码来源:http://wenwen.sogou.com/z/q710937394.htm

新增功能:可以自行选择继续出题还是退出程序,加入了一个简单的多运算符运算。 

语言:C语言

编译环境:VC++6.0

运行环境:Windows

BUG:暂未发现BUG

GitHub地址:https://github.com/Devilingg/-/blob/master/%E8%BF%90%E7%AE%97

 1 #include<stdio.h>
 2 #include<time.h>
 3 #include<stdlib.h>
 4 #include<conio.h>
 5 
 6 int main(){
 7     int a,b,c,d,n;
 8     char m;
 9 start:srand(time(0));
10     a=rand()%100;
11     b=rand()%100;
12     n=rand()%100;
13     c=rand()%4;
14     switch(c){
15         case 0:printf("%d+%d=",a,b);break;
16         case 1:printf("%d-%d=",a,b);break;
17         case 2:printf("%d*%d=",a,b);break;
18         case 3:printf("%d+%d-%d=",a,b,n);break;
19         case 4:if(b==0){
20 
21                     while(b==0){
22                     a=rand()%100;
23                     b=rand()%100;
24                     printf("%d/%d=",a,b);
25         }
26     }
27                 else
28                     printf("%d/%d=",a,b);
29                 break;
30     }
31     scanf("%d",&d);
32     getchar();
33     switch(c){
34         case 0:if(d==a+b)
35                     printf("You are right\n");
36                     else
37                         printf("You are wrong\n");
38                 break;
39         case 1:if(d==a-b)
40                     printf("You are right\n");
41                     else
42                         printf("You are wrong\n");
43                 break;
44         case 2:if(d==a*b)
45                     printf("You are right\n");
46                     else
47                         printf("You are wrong\n");
48                 break;
49         case 3:if(d==a+b-n)
50                     printf("You are right\n");
51                     else
52                         printf("You are wrong\n");
53                 break;
54         case 4:if(d==a/b)
55                     printf("You are right\n");
56                     else
57                         printf("You are wrong\n");
58                 break;
59 
60     }
61     printf("继续请输入Y,退出请输入任意字符。");
62     scanf("%c",&m);
63     getchar();
64     if(m=='Y')
65         goto start;
66 
67         return 0;
68 }

 

posted @ 2017-09-14 22:47  怪蜀黍的橘子  阅读(128)  评论(0编辑  收藏  举报