#include<iostream> #include <stdlib.h> #include <time.h> #define random(x) (rand()%x) using namespace std; void main() { srand((int)time(0)); for(int j=0;j<30;j++) { int i; i=rand()%2; switch(i) { case(0): { int a,b,x; char y; x=rand()%4; switch(x) { case(0):y=‘+‘;break; case(1):y=‘-‘;break; case(2):y=‘*‘;break; case(3):y=‘/‘;break; } a=random(100); b=random(100); if(y==‘/‘) { if(b==0) { do {b=random(100);} while(b==0); } cout<<a<<y<<b<<"="<<endl;break; } case(1): { int a,b,c,d,x; char y; x=rand()%4; switch(x) { case(0):y=‘+‘;break; case(1):y=‘-‘;break; case(2):y=‘*‘;break; case(3):y=‘/‘;break; } a=random(100); b=random(100); c=random(100); d=random(100); if(a>b) cout<<"("<<b<<"/"<<a<<")"; else { if(b==0) { do{b=random(100);} while(b==0); } cout<<"("<<a<<"/"<<b<<")"; } cout<<y; if(c>d) cout<<"("<<d<<"/"<<c<<")"; else { if(d==0) { do{d=random(100);} while(d==0); } cout<<"("<<c<<"/"<<d<<")"; } cout<<"="<<endl;break; } } } } }
时间: 2024-10-10 12:21:38