设计思想:出三十道一百以内数的随机四则运算题目,先随机两个一百以内的数字,再通过随机数确定四则运算算符,最后通过for循环输出三十道

源代码程序:

#include <stdlib.h>
#include <iostream.h>
#include <conio.h>
#include <time.h>
int main()
{
int a = 0;
int b = 0;
int mode = 0;//0:加 1:减 2:乘 3:除
int i = 0;
srand((unsigned)time( NULL ) ); //初始化随机数发生器,使得每次运行生成的随机数不同
for(i=0;i<30;i++) //做三十题
{
a = rand() % 100; //生成一个0~99之间的随机数
b = rand() % 100; //生成一个0~99之间的随机数
mode = rand() % 4; //生成一个0~3之间的随机数,代表运算符
printf("%d", a); //打印算式
switch(mode) //确定运算符
{
case 0:
printf("+%d = \n", b );
break;
case 1:
printf("-%d = \n", b );
break;
case 2:
printf("*%d = \n", b );
break;
case 3:
printf("/%d = \n", b );
break;
default:
printf("somethingis wrong!\n");
break;
}
}
return 0;
}

程序截图;

随机四则运算 C语言

上课未完成原因:知识遗忘比较多,基本技巧不熟练

相关文章:

  • 2021-10-20
  • 2021-08-24
  • 2021-09-30
  • 2021-07-08
  • 2021-08-11
  • 2021-06-29
  • 2021-07-28
  • 2021-10-01
猜你喜欢
  • 2021-08-17
  • 2022-01-23
  • 2021-11-05
  • 2021-12-05
  • 2021-12-23
相关资源
相似解决方案