一个能自动生成小学四则运算题目的程序

源代码

#include<stdio.h>

#include<stdlib.h>
#include<time.h>
main()
{
int a,b,op,os;

printf(" [天天练,Baby们来挑战吧!] ");
aq1: printf("选择您想挑战的运算法则 ");
printf("1.加法 2.减法 3.乘法 4.除法 ");
scanf("%d",&op);
switch(op)
{
aq: case 1:
srand((unsigned)time(NULL));
a=rand()%100+1;b=rand()%100+1;
printf("题目为:%d + %d = ? ",a,b);
printf("1.查看答案 2.做下一题 ");
scanf("%d",&os);
if(os==1)
{printf("%d + %d =%d ",a,b,a+b);
goto aq1;
}
else
goto aq;
break;
at: case 2:a=rand()%100+1;b=rand()%100+1;
printf("题目为:%d - %d = ? ",a,b);
printf("1.查看答案 2.做下一题 ");
scanf("%d",&os);
if(os==1)
{printf("%d - %d =%d ",a,b,a-b);
goto aq1;
}
else
goto at;
break;
aq2: case 3:
a=rand()%100+1;b=rand()%100+1;
printf("题目为:%d * %d = ? ",a,b);
printf("1.查看答案 2.做下一题 ");
scanf("%d",&os);
if(os==1)
{printf("%d * %d =%d ",a,b,a*b);
goto aq1;
}
else
goto aq2;
aq3: case 4:
a=rand()%100+1;b=rand()%100+1;
printf("题目为:%d / %d = ? ",a,b);
printf("1.查看答案 2.做下一题 ");
scanf("%d",&os);
if(os==1)
{printf("%d / %d =%d ",a,b,a/b);
goto aq1;
}
else
goto aq3;
break;
}
}

截图

 

总结

做得有点仓促所以做得不是很好,除法方面小数跟负数都不能够处理,这方面没有考虑进去。

原文地址:https://www.cnblogs.com/zhangqicong/p/4369601.html