题目要求随机生成30道四则运算题目,则主体部分采用循环结构,运算符的随机产生则用随机数的模运算控制

源代码:

#include<iostream>
using namespace std;
void main()
{
 for(int i=0;i<30;i++)
 {
  int a=rand()%100;
  int b=rand()%100;
  int c=rand()%4;
  switch(c)
  {
  case(0):
   cout<<a<<"+"<<b<<"="<<endl;
   break;
  case(1):
   cout<<a<<"-"<<b<<"="<<endl;
   break;
  case(2):
   cout<<a<<"*"<<b<<"="<<endl;
   break;
        case(3):
   cout<<a<<"/"<<b<<"="<<endl;
   break;
  }
 }
}

运行结果截图:

软件工程随堂练习——随机四则运算

 

相关文章:

  • 2021-10-01
  • 2021-08-13
  • 2021-07-28
  • 2021-05-30
  • 2021-10-24
  • 2022-01-23
  • 2021-11-04
  • 2021-07-07
猜你喜欢
  • 2021-06-13
  • 2021-05-23
  • 2022-01-19
  • 2021-06-03
  • 2021-05-30
  • 2021-09-30
  • 2022-03-08
相关资源
相似解决方案