四则运算1

要求:用程序实现随机生成三十道100以内的四则运算题。

由c++编写,循环输出两个随机数以及随机数中间的运算符号变量,程序结束

 1 #include<iostream>
 2 #include<string>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int x, y, a;
 8     string b;
 9     for (int i=0; i < 30; i++)
10     {
11         x = rand() % 100;
12         y = rand() % 100;
13         a = rand() % 4;
14         switch (a)
15         {
16         case 0:b = "+"; break;
17         case 1:b = "-"; break;
18         case 2:b = "*"; break;
19         case 3:b = "/"; 
20         }
21         cout << x+1 << " " << b << " " << y+1 << " =" << endl;
22     }
23     system ("pause");
24     return 0;
25 }

实现截图:

猜你喜欢

转载自www.cnblogs.com/Kirito-math/p/9753624.html