#include<iostream> #include<stdlib.h> using namespace std; #define MAX 10000 #include <ctime> #include <cstdlib> void display() { char q[4][2]={"+","-","*","/"}; int a,b,k,m,n,o,p; cout<<"请输入定制数量"<<endl; cin>>k;//定制数量 cout<<endl; cout<<"请输入数值范围(如 10 50)"<<endl; cin>>m>>n; cout<<endl;//数值范围 cout<<"0.无乘除法"<<endl; cout<<"1.有乘除法"<<endl; cin>>o;//有无乘除 0 无 1有 cout<<endl; if(o!=0||o!=1) { cout<<"输入错误,重新输入"<<endl; cout<<"0.无乘除法"<<endl; cout<<"1.有乘除法"<<endl; cin>>o; cout<<endl; } if(m<n) { int temp=n; n=m; m=temp; } if(o!=0&&o==1) { cout<<endl; cout<<"0.无余数"<<endl; cout<<"1.有余数"<<endl; cin>>p;//有无余数 0无 1有 } int d[MAX][3]; srand(time(0)); for(int i=0;i<k;i++) { d[i][0]=rand()%(m-n)+n; d[i][1]=rand()%(m-n)+n; d[i][2]=rand()%(m-n)+n; a=rand()%4; b=rand()%4; if(o==1) { a=rand()%4; b=rand()%4; } else { a=rand()%2; b=rand()%2; } if(o==0) { cout<<"第"<<i+1<<"道题:"<<d[i][0]<<q[a]<<d[i][1]<<q[b]<<d[i][2]<<"="<<endl; } else if(p==0) { if(((d[i][0]%d[i][1]==0&&a==3)&&(d[i][1]%d[i][2]==0&&b==3))||(d[i][0]%d[i][1]==0&&a==3)||(d[i][1]%d[i][2]==0&&b==3)) cout<<"第"<<i+1<<"道题:"<<d[i][0]<<q[a]<<d[i][1]<<q[b]<<d[i][2]<<"="<<endl; else i=i-1; } else cout<<"第"<<i+1<<"道题:"<<d[i][0]<<q[a]<<d[i][1]<<q[b]<<d[i][2]<<"="<<endl; } } int main() { display(); return 0; }
实验截图
实验总结:输入0和1时程序正常运行,输入的不是0和1时提示有错误重新输入。通过本次测试发现程序还不够完善,以后做好程序后都要进行测试把有缺陷的地方找出来完善。