个人项目一:给二柱子编30道四则运算题
编码:
#include<iostream.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int x,y,z,t;
srand(time(NULL));
cout<<"四则运算题"<<endl;
for(int i=0;i<30;i++)
{
x=rand()%100;
y=rand()%100;
z=rand()%4;
switch(z)
{
case 0:
cout<<x<<"+"<<y<<"="<<endl;
break;
case 1:
if(x<y)
{
t=x;
x=y;
y=t;
}
cout<<x<<"-"<<y<<"="<<endl;
break;
case 2:
cout<<x<<"*"<<y<<"="<<endl;
break;
case 3:
if(y!=0)
{
cout<<x<<"/"<<y<<"="<<endl;
}
else
{
i=i-1;
}
break;
default:
cout<<"error"<<endl;
break;
}
}
return 0;
#include<stdlib.h>
#include<time.h>
int main()
{
int x,y,z,t;
srand(time(NULL));
cout<<"四则运算题"<<endl;
for(int i=0;i<30;i++)
{
x=rand()%100;
y=rand()%100;
z=rand()%4;
switch(z)
{
case 0:
cout<<x<<"+"<<y<<"="<<endl;
break;
case 1:
if(x<y)
{
t=x;
x=y;
y=t;
}
cout<<x<<"-"<<y<<"="<<endl;
break;
case 2:
cout<<x<<"*"<<y<<"="<<endl;
break;
case 3:
if(y!=0)
{
cout<<x<<"/"<<y<<"="<<endl;
}
else
{
i=i-1;
}
break;
default:
cout<<"error"<<endl;
break;
}
}
return 0;
}
运行结果截图:
![](https://img2018.cnblogs.com/blog/1500175/201810/1500175-20181008001117214-1969668685.png)