小学四则运算1.0
//信1301-1班 张鹏宇 四则运算 #include<iostream> #include<stdio.h> #include<time.h> using namespace std; void main(){ int num1,num2,num3,num4; int a,b; int i; srand((unsigned)time(NULL)); for(i=0;i<30;i++){ //30个 b=rand()%2; if(b==0){ //num1整数 num1=rand()%101; b=rand()%2; if(b==0){ //num2整数 num2=rand()%101; a=rand()%4; if(a==0) cout<<num1<<"+"<<num2<<"="<<endl; if(a==1) cout<<num1<<"-"<<num2<<"="<<endl; if(a==2) cout<<num1<<"*"<<num2<<"="<<endl; if(a==3){ if(num2==0){ for(;num2==0;) num2=rand()%101; cout<<num1<<"/"<<num2<<"="<<endl; } else cout<<num1<<"/"<<num2<<"="<<endl; } } else{ //num2分数 num2=rand()%101; num3=rand()%101; for(;num2>=num3;) num3=rand()%102; for(;num3==0;) num3=rand()%102; a=rand()%4; if(a==0) cout<<num1<<"+"<<num2<<"/"<<num3<<"="<<endl; if(a==1) cout<<num1<<"-"<<num2<<"/"<<num3<<"="<<endl; if(a==2) cout<<num1<<"*"<<num2<<"/"<<num3<<"="<<endl; if(a==3){ if(num2==0){ for(;num2==0;) num2=rand()%101; cout<<num1<<"/"<<"("<<num2<<"/"<<num3<<")"<<"="<<endl; } else cout<<num1<<"/"<<"("<<num2<<"/"<<num3<<")"<<"="<<endl; } } } if(b==1){ //num1分数 num1=rand()%101; num2=rand()%101; for(;num2==0;) num2=rand()%101; b=rand()%2; if(b==0){ //num2整数 num3=rand()%101; a=rand()%4; cout<<num1<<"/"<<num2<<"+"<<num3<<"="<<endl; if(a==1) cout<<num1<<"/"<<num2<<"-"<<num3<<"="<<endl; if(a==2) cout<<num1<<"/"<<num2<<"*"<<num3<<"="<<endl; if(a==3){ if(num3==0){ for(;num3==0;) num3=rand()%101; cout<<num1<<"/"<<num2<<"+"<<num3<<"="<<endl; } else cout<<num1<<"/"<<num2<<"+"<<num3<<"="<<endl; } } else{ //num2分数 num3=rand()%101; num4=rand()%101; for(;num3>=num4;) num4=rand()%102; for(;num4==0;) num4=rand()%102; a=rand()%4; if(a==0) cout<<num1<<"/"<<num2<<"+"<<num3<<"/"<<num4<<"="<<endl; if(a==1) cout<<num1<<"/"<<num2<<"-"<<num3<<"/"<<num4<<"="<<endl; if(a==2) cout<<num1<<"/"<<num2<<"*"<<num3<<"/"<<num4<<"="<<endl; if(a==3){ if(num3==0){ for(;num3==0;) num3=rand()%101; } else cout<<"("<<num1<<"/"<<num2<<")"<<"/"<<"("<<num3<<"/"<<num4<<")"<<"="<<endl; } } } } }
posted on 2016-03-04 15:57 foorever_宇 阅读(170) 评论(1) 编辑 收藏 举报