二柱子四则运算初级版
100以内运算
源代码:
1 #include<stdio.h> 2 #include<iostream> 3 #include<time.h> 4 #include<string> 5 using namespace std; 6 int main() 7 {srand( (unsigned)time( NULL ) ); 8 int i,k; 9 int *s1,*s2; 10 string *sc; 11 string g[4]={"+","-","×","÷"}; 12 cout<<"该程序输出30道题目,题为100一内的加减乘除"<<endl; 13 s1=new int[30]; 14 s2=new int[30]; 15 sc=new string[30]; 16 cout<<"以下为随机选取的题目:"<<endl; 17 for(i=1;i<=30;i++) 18 { 19 sc[i]=g[rand()%4]; 20 s1[i]=rand()%100; 21 s2[i]=rand()%100;//随机取运算符和数 22 if(i==1) 23 {cout<<s1[i]<<sc[i]<<s2[i]<<"= "; 24 } 25 else 26 { 27 for(k=0;k<i;k++)//避免重复 28 { 29 if(sc[k]==sc[i]&&s1[k]==s1[i]&&s2[k]==s2[i]) 30 { 31 i--; 32 break; 33 } 34 else//比较到最后一个的时候输出题目 35 { 36 if(k==i-1) 37 {cout<<s1[i]<<sc[i]<<s2[i]<<"= "; 38 } 39 } 40 } 41 } 42 if(i%3==0)//每行输出3题目 43 { 44 cout<<endl; 45 cout<<endl;//每行之间空一行 46 } 47 } 48 return 0; 49 }
运行截图: