通过函数产生随机数,然后随机生成加减乘除运算并输出
#include<iostream>
#include<ctime>
using namespace std;
void main()
{
int a,b,c;
srand(unsigned(time(NULL)));
for(int i=0;i<30;i++)
{
a=rand()%99+1;
b=rand()%99+1;
c=rand()%4+1;
switch(c)
{
case 1:cout<<a<<"+"<<b<<"="<<endl;break;
case 2:{
if(a>b)
cout<<a<<"-"<<b<<"="<<endl;
else
cout<<b<<"-"<<a<<"="<<endl;
break;
}
case 3:cout<<a<<"*"<<b<<"="<<endl;break;
case 4:cout<<a<<"/"<<b<<"="<<endl;break;
}
}
}
时间: 2024-10-27 07:09:20