#include <stdio.h> //为小学一年级学生随机出10道题,加法或减法随机出现,保证涉及到的数在0-9之间,结果不能出现负数 //程序运行输入结果后提示对或错,最后并统计做对了几道题,及最后得分(每题10分计算) #include <math.h> #include <stdlib.h> //#include <time.h> main() { int i,a,b,c=0,sum=0,fu,jieguo,an; srand(time()) ; for(i=1;i<=3;i++) { a=rand()%(5)+1; b=rand()%(2)+1; while(a<b) { a=rand()%(5)+1; b=rand()%(2)+1; } fu=rand()%2; if(fu==1) printf("a+b=%d+%d=",a,b),jieguo=a+b; else printf("a-b=%d-%d=",a,b),jieguo=a-b; scanf("%d",&an); if(jieguo==an) printf("做对了!!\n"),c++,sum=sum+10; else printf("做错了!!\n"); } printf("共做对%d题,共计%d分",c,sum); getchar(); }
标签:10,C语言,出题,随机,每题,include From: https://www.cnblogs.com/xkdn/p/16767886.html