2.2.2设计思路和遇到的问题
设计思路:和前面的第二次作业相似,但需要使用随机rand函数,添加进去即可。在开头多弄几个函数。
遇到的问题:开始不知道怎么随机得到加减乘除,那数是怎么生成的,通过资料查询就明白了点,但还不是特别理解。
2.2.3程序结果截图
![](https://img2018.cnblogs.com/blog/1809911/202002/1809911-20200211104301732-1989546492.png)
![](https://img2018.cnblogs.com/blog/1809911/202002/1809911-20200211104345579-1323594045.png)
![](https://img2018.cnblogs.com/blog/1809911/202002/1809911-20200211104429568-1444419907.png)
2.2.4程序代码
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
void menu();
void help();
void error();
void operation_1();void one();
void operation_2();void two();
void operation_3();void three();
int main()
{
int m;
printf("========== 口算生成器 ==========
欢迎使用口算生成器 :
希望早日开学
");
printf("
");
help();
while(1)
{
menu();
scanf("%d",&m);
switch(m)
{
case 1:operation_1();break;
case 2:operation_2();break;
case 3:operation_3();break;
case 4:help();break;
}
printf("
");
if(m==5) break;
if(m>5||m<1) error();
}
return 0;
}
void help()
{
printf("帮助信息
您需要输入命令代号来进行操作, 且
");
printf("一年级题目为不超过十位的加减法;
二年级题目为不超过百位的乘除法;
""三年级题目为不超过百位的加减乘除混合题目.
");
printf("
");
}
void menu()
{
printf("操作列表:
1)一年级 2)二年级 3)三年级
4)帮助 5)退出程序
请输入代号:");
}
void error()
{
printf("错误程序,请重新输入正确数值。");
printf("
");
}
void operation_1()
{
printf("请输入题目个数>");
one();
}
void operation_2()
{
printf("请输入题目个数>");
two();
}
void operation_3()
{
printf("请输入题目个数>");
three();
}
void one()
{
int x,a,b,c;
scanf("%d",&x);
printf("现在是一年级题目:
");
srand((unsigned)time(NULL));
for(int i=1;i<=x;i++)
{
a=rand()%10;
b=rand()%10;
c=rand()%2;
switch(c){
case 0:printf("%d + %d = ___",a,b);break;
default: printf("%d - %d = ___",a,b);
}
printf("
");
}
}
void two()
{
int x,a,b,c;
scanf("%d",&x);
printf("现在是二年级题目:
");
srand((unsigned)time(NULL));
for(int i=1;i<=x;i++)
{
a=rand()%100;
b=rand()%100;
c=rand()%4;
if(c==0)
printf("%3d * %3d = ___",a,b);
else
printf("%3d / %3d = ___",a,b);
printf("
");
}
}
void three()
{
int x,a,b,c;
scanf("%d",&x);
printf("现在是三年级题目:
");
srand((unsigned)time(NULL));
for(int i=1;i<=x;i++)
{
a=rand()%100;
b=rand()%100;
c=rand()%4;
switch(c)
{
case 0:printf("%3d + %3d = ___",a,b);break;
case 1:printf("%3d - %3d = ___",a,b);break;
case 2:printf("%3d * %3d = ___",a,b);break;
case 3:printf("%3d / %3d = ___",a,b);break;
}
printf("
");
}
}
2.2.5Gitee上传截图与链接
![](https://img2018.cnblogs.com/blog/1809911/202002/1809911-20200211112038708-1016152414.png)
![](https://img2018.cnblogs.com/blog/1809911/202002/1809911-20200211111921783-45497472.png)
https://gitee.com/deng_zhi_zhu/dashboard