20150324 练习1 四则运算题目的程序20150324 练习1 四则运算题目的程序

源代码:

#include<stdio.h>
#include<stdlib.h>
main()
{int a,b,op,os;
printf(" [每课一练 妈妈再也不用担心我的学习]\n");
aq1: printf("选择您想挑战的运算法则\n");
printf("1.加法 2.减法 3.乘法 4.除法\n");
scanf("%d",&op);
switch(op)
{
aq: case 1:
a=rand();b=rand();
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();b=rand();
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();b=rand();
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();b=rand();
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;
}
}

总结:

1.rand()涵数没有真正实现随 用srand会更好

2.过多的goto使用 使整体结构破坏

3.没有设置rand的范围

 

相关文章:

  • 2021-10-01
  • 2021-09-22
  • 2021-06-25
  • 2021-09-22
  • 2021-07-16
  • 2021-10-20
猜你喜欢
  • 2021-08-08
  • 2021-12-26
  • 2022-01-09
  • 2021-08-10
  • 2021-12-28
  • 2022-02-13
相关资源
相似解决方案