程序流程:
代码如下:
1 #include<iostream> 2 #include<stdio.h> 3 using namespace std; 4 int main() 5 { 6 int n,m; 7 int z,x; 8 int t=0; 9 void f(int a,int b,int c); 10 printf("请输入生成的题目数(1-10000): "); 11 cin>>n; 12 printf("请输入是否有乘除法:是输入1,否输入0 "); 13 cin>>m; 14 if(m==1) 15 m=4; 16 else 17 m=2; 18 printf("请输入数的范围a,b(0-500000):a,b以空格隔开,保证a<b "); 19 cin>>z>>x; 20 x=x+1-z; 21 printf("题目生成: "); 22 while(n--) 23 { 24 t++; 25 f(m,x,z); 26 if(t==5) 27 { 28 printf(" "); 29 t=0; 30 } 31 else 32 printf(" "); 33 } 34 return 0; 35 } 36 void f(int a,int b,int c) 37 { 38 int m,n,k; 39 m=(rand()%b)+c; 40 cout<<m; 41 k=rand()%a; 42 switch(k) 43 { 44 case 0:cout<<"+";break; 45 case 1:cout<<"-";break; 46 case 2:cout<<"*";break; 47 case 3:cout<<"/";break; 48 } 49 if(k==3) 50 while(1) 51 { 52 n=(rand()%b)+c; 53 if(n<=m) 54 break; 55 } 56 else 57 n=(rand()%b)+c; 58 cout<<n<<"="; 59 }