1、#include#include#includeint a,x,y,z,t;int score=0;int sign;/加减符号 /*自动生成0-number内的1个随机数*/int numCreator(int number) int k; k=rand()%number; return(k);/*自动生成+或-号, 0为减号,1为加号*/int signCreator()int j=numCreator(100);return(j%2); /*自动生成题目*/ void quizCreator()sign=signCreator();x=numCreator(100);/x为0-100中随
2、机一个数 /*加法题目*/ if(sign=0)y=numCreator(100-x);z=x+y;printf(%3d+%3d=?n,x,y);/*减法题目*/elsey=numCreator(x);z=x-y;printf(%3d-%3d=?n,x,y); /*测验运行,并统计分数*/void quizOperator()char answer10; int i;quizCreator();scanf(%s,&answer); /判断录入是否为数字for(i=0;answeri!=0;i+)if(answeri9) printf(答案只能是数字!n); break;a=atoi(answe
3、r);if(a=z) printf(回答正确!n);printf(加10分! _n); score=score+10;else printf(回答错误n);printf(正确答案是:%3dn,z); void main()int i;FILE *fp; fp=fopen(comment.txt,w);srand(time(NULL);printf(计算机辅助教学n);printf(Welcome to 数学测验n);printf(共10道题目n);for(i=0;i10;i+)quizOperator();printf(你的分数是%dn,score);/根据总分判断学生的成绩的等级switch
4、(score/10)case 10:case 9:fprintf(fp,你的总成绩为%d分,优秀!您一共答对了%d题,答错了%d题。n,score,score/10,10-score/10);printf(优秀n);printf(你的总成绩为%d分,优秀!您一共答对了%d题,答错了%d题。n,score,score/10,10-score/10);break;case 8:fprintf(fp,你的总成绩为%d分,良好!您一共答对了%d题,答错了%d题。n,score,score/10,10-score/10);printf(良好n);printf(你的总成绩为%d分,良好!您一共答对了%d题
5、,答错了%d题。n,score,score/10,10-score/10);break;case 7:case 6:fprintf(fp,你的总成绩为%d分,合格!您一共答对了%d题,答错了%d题。n,score,score/10,10-score/10); printf(合格n); printf(你的总成绩为%d分,合格!您一共答对了%d题,答错了%d题。n,score,score/10,10-score/10);break;default:fprintf(fp,你的总成绩为%d分,未达标!您一共答对了%d题,答错了%d题。n,score,score/10,10-score/10);printf(未达标,请再接再厉!n); printf(你的总成绩为%d分,未达标!您一共答对了%d题,答错了%d题。n,score,score/10,10-score/10);break;