作业二:自动生成四则运算

主要功能:本程序可以自动生成四则运算,还有选择运算法则和查看答案的功能。
设计思想: 可以选择运算法则,可以随机出现计算题,可出现答案,也可直接进入下一题。
源代码:
#include<stdio.h> #include<stdlib.h> #include<time.h> main() { int a,b,op,os; aq1: printf("选择您想挑战的运算法则\n"); printf("1.加法 2.减法 3.乘法 4.除法\n"); scanf("%d",&op); switch(op) { aq: case 1: srand((unsigned)time(NULL)); a=rand()%100+1;b=rand()%100+1; printf("题目为:%d + %d = ?\n\n",a,b); printf("1.查看答案 2.做下一题\n"); scanf("%d",&os); if(os==1) {printf("%d + %d =%d\n\n\n",a,b,a+b); goto aq1; } else goto aq; break; at: case 2:a=rand()%100+1;b=rand()%100+1; printf("题目为:%d - %d = ?\n\n",a,b); printf("1.查看答案 2.做下一题\n"); scanf("%d",&os); if(os==1) {printf("%d - %d =%d\n\n\n",a,b,a-b); goto aq1; } else goto at; break; aq2: case 3: a=rand()%100+1;b=rand()%100+1; printf("题目为:%d * %d = ?\n\n",a,b); printf("1.查看答案 2.做下一题\n"); scanf("%d",&os); if(os==1) {printf("%d * %d =%d\n\n\n",a,b,a*b); goto aq1; } else goto aq2; aq3: case 4: a=rand()%100+1;b=rand()%100+1; printf("题目为:%d / %d = ?\n\n",a,b); printf("1.查看答案 2.做下一题\n"); scanf("%d",&os); if(os==1) {printf("%d / %d =%d\n\n\n",a,b,a/b); goto aq1; } else goto aq3; break; } }
运行截图:
总结:这一次做的还很不成熟,做的时候出现了很多错误,参考了网上同类型的程序之后,才发现了错误所在,在参考了网上的程序之后,思路也渐渐打开了,做完之后再看自己做的程序,很有成就感,很有收获,相信在接下来的学习中,我会收获更多。

 

posted @ 2016-03-16 22:31  13-计科-1王乃宽  阅读(162)  评论(1编辑  收藏  举报