这个作业属于哪个课程 | https://edu.cnblogs.com/campus/zswxy/CST2019-2 |
这个作业要求在哪里 | https://edu.cnblogs.com/campus/zswxy/CST2019-2/homework/10279 |
这个作业的目标 | 加入问题的答案 |
作业正文 | |
参考文献 | https://www.runoob.com/cprogramming/c-function-rand.html https://zhidao.baidu.com/question/271899014.html |
1.设计思路和遇到的问题
1.在后面的三年级那一栏非常麻烦,需要吧所以情况都考虑,非常心累啊
2.整体来说比地三次简单,基本应付得过来
2.程序结果截图
3. 程序代码
#include
#include
#include
void one(){
srand(time(NULL));
int x,y,i,n;
char op[2]={'+','-'};
printf("现在是一年级题目:\n请输入生成题目的个数:");
scanf("%d",&n);
for(i=n;i>0;i--){
x=rand()%11;
y=rand()%11;
switch(op[rand()%2])
{
case '+': printf("%d + %d = %d\n",x,y,x+y); break;
case '-': if(x
else printf("%d - %d = %d\n",x,y,x-y); break;
}
}
printf("\n\n");
}
void two(){
srand(time(NULL));
int x,y,i,n;
char op[2]={'*','/'},c;
printf("现在是二年级题目:\n请输入生成题目的个数:");
scanf("%d",&n);
for(i=n;i>0;i--){
x=rand()%101;
y=rand()%101;
c=op[rand()%2];
switch(op[rand()%2])
{
case'*':if(x==0||y==0)
printf("0 \n");
else
printf("%d * %d = %d\n",x,y,x*y);break;
case'/':if(c=='/'&&y==0)
y=rand()%100+1;
else if(x==0)
printf("0 \n");
else printf("%d / %d = %g\n",x,y,(double)x/y);
}
}
printf("\n\n");
}
void three(){
srand(time(NULL));
int x,y,z,i,n;
char op[4]={'*','/','+','-'},op1,op2;
printf("现在是三年级题目:\n请输入生成题目的个数:");
scanf("%d",&n);
for(i=n;i>0;i--){
x=rand()%101;
op1=op[rand()%4];
y=rand()%11;
if(op1=='/'&&y==0)
y=rand()%10+1;
op2=op[rand()%4];
z=rand()%11;
if(op2=='/'&&z==0)
z=rand()%10+1;
switch(rand()%12)
{
case 1: printf("%d + %d - %d = %d\n",x,y,z,x+y-z); break;
case 2: printf("%d + %d * %d = %d\n",x,y,z,x+y*z); break;
case 3: printf("%d + %d / %d = %g\n",x,y,z,(double)x+y/z); break;
case 4: printf("%d - %d + %d = %d\n",x,y,z,x-y+z); break;
case 5: printf("%d - %d * %d = %d\n",x,y,z,x-y*z); break;
case 6: printf("%d - %d / %d = %g\n",x,y,z,(double)x-y/z); break;
case 7: printf("%d * %d + %d = %d\n",x,y,z,x*y+z); break;
case 8: printf("%d * %d - %d = %d\n",x,y,z,x*y-z); break;
case 9: printf("%d * %d / %d = %g\n",x,y,z,(double)x*y/z);break;
case 10: printf("%d / %d + %d = %g\n",x,y,z,(double)x/y+z); break;
case 11: printf("%d / %d - %d = %g\n",x,y,z,(double)x/y-z); break;
case 12: printf("%d / %d * %d = %g\n",x,y,z,(double)x/y*z); break;
}
}
printf("\n\n");
}void menu(){
printf("操作列表\n1)一年级 2)二年级 3)三年级\n4)帮助 5)退出程序\n\n请输入操作>");
}
void help(){
printf("帮助信息\n您需要输入命令代号来进行操作, 且\n一年级题目为不超过十位的加减法;\n二年级题目为不超过百位的乘除法;\n三年级题目为不超过百位的加减乘除混合题目.\n\n");
}
void error(){
printf("Error!!!\n错误操作指令, 请重新输入\n\n");
}
int main(){
int x=0;
printf("========== 口算生成器 ==========\n欢迎使用口算生成器 :\n\n");
help();
menu();
while(x!=5){
scanf("%d",&x);
printf("<执行操作:)\n\n");
switch(x){
case 1:one();break;
case 2:two();break;
case 3:three();break;
case 4:help();break;
case 5:printf("程序结束,欢迎下次使用 任意键结束......");break;
default:error();break;
}if (x!=5)menu();
}
return 0;
}
4. Gitee上传截图与链接
码云链接‘
https://gitee.com/wangdongfk