代码:
#include <iostream>
#include <time.h>
using namespace std; void main()
{
srand((int)time(NULL)); //每次执行种子不同,生成不同的随机数
int a, b, c, d, e, i, mark,opt;
for (i = ; i < ; i++)
{
opt = + rand() % ;//随机生成1或者2来表示整数和真分数
a = + rand() % ;//将1到100内的数随机赋予a
b = + rand() % ;//将1到100内的数随机赋予b
c = + rand() % ;//将1到100内的数随机赋予c
d = + rand() % ;//将1到100内的数随机赋予d
if (opt == )
{
mark = + rand() % ;//随机生成1-4来分别表示四个运算符
cout << a;
switch (mark)
{
case :cout << "+"; break;
case :cout << "-"; break;
case :cout << "×"; break;
case :cout << "÷"; break;
}
cout << b << "=" << endl;
}
if (opt == )
{
if (a > b)
{
e = a;
a = b;
b = e;
}
cout << "(" << a << "/" << b <<")";
mark = + rand() % ;
switch (mark)
{
case :cout << "+"; break;
case :cout << "-"; break;
case :cout << "×"; break;
case :cout << "÷"; break;
}
if (c > d)
{
e = c;
c = d;
d = e;
}
cout << "(" << c << "/" << d << ")" <<"="<< endl;
} }
}