30道四则运算题的第一次升级
1 /** 2 作者:程鹏远 3 题目:30道2年纪四则运算题目 4 */ 5 #include <iostream.h> 6 #include <stdlib.h> 7 int main() 8 { 9 int a,b,c; 10 for(int i=0;i<30;i++) 11 { 12 cout<<"第"<<i+1<<"题: "; 13 a=rand()%100;//x+rand()%(y-x+1)随机生成【x,y】内的整数 14 b=rand()%100; 15 c=rand()%4; 16 switch (c) 17 { 18 case 1: 19 cout<<a<<"+"<<b<<"="<<endl; 20 break; 21 case 2: 22 if(a>b){cout<<a<<"-"<<b<<"="<<endl;} 23 else{cout<<b<<"-"<<a<<"="<<endl;} 24 break; 25 case 3: 26 cout<<a<<"*"<<b<<"="<<endl; 27 break; 28 case 0: 29 30 int j=0; 31 while((j<100000)&&(a!=0)&&(b!=0)&&(a%b==0)){cout<<a<<"/"<<b<<"="<<endl;i++;j++;} 32 33 if((a!=0)&&(b!=0)&&(a%b==0)){cout<<a<<"/"<<b<<"="<<endl;i++;} 34 else{ 35 int j=0; 36 while(j<100000) 37 { 38 a=rand()%1000;//x+rand()%(y-x+1)随机生成【x,y】内的整数 39 b=rand()%100; 40 if((a!=0)&&(b!=0)&&(a%b==0)){cout<<a<<"/"<<b<<"="<<endl;i++;j=100000;j++;} 41 else{j++;} 42 } 43 } 44 45 break; 46 } 47 } 48 return 0; 49 }