源代码如下所示:
#include<iostream.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int a,b,c,t;
srand(time(NULL));
for(int i=0;i<30;i++)
{
a=rand()%100;
b=rand()%100;
c=rand()%4;
switch(c)
{
case 0:
cout<<a<<"+"<<b<<"="<<endl;
break;
case 1:
if(a<b)
{
t=a;
a=b;
b=t;
}
cout<<a<<"-"<<b<<"="<<endl;
break;
case 2:
cout<<a<<"*"<<b<<"="<<endl;
break;
case 3:
if(b!=0)
{
cout<<a<<"/"<<b<<"="<<endl;
}
else
{
i=i-1;
}
break;
}
}
cout<<"30道数学测试题结束"<<endl;
return 0;
}
运行界面:
时间: 2024-10-19 15:27:41