#include<stdio.h> #include<stdlib.h> #include<string.h> main() { int i,cd,j; int cc,kh,ykh,zkh; int n,cz,count=0,count1=0; char ys[4][1]={"+","-","*","/"}; char khs[4][1]={"","(","",")"}; printf("请输入生成题目的数量"); scanf("%d",&n); printf("是否有乘除法(1有 2没有)"); scanf("%d",&cc); // printf("是否有括号(1有 2没有)"); // scanf("%d",&kh); printf("请输入数值范围:"); scanf("%d",&cz); if(cc==1) cc=4; else cc=2; for(i=0;i<n;i++) {cd=2+rand()%4; for(j=0;j<cd-1;j++) printf("%d %1c ",rand()%cz,ys[rand()%cc][0]); printf(" %d = ",rand()%cz); } }
运行结果:
对随机插入括号表示不懂!试了好多方法都失败了!到目前还没找到有效的方法!