C语言实现小学加减法的测试题,统计分数
总之,家里来了个幼儿园升小学的侄儿子,写了个随机数考他的数学基础。代码简单易懂,纯属娱乐。
#include <stdio.h>
#include<stdlib.h>
#include<time.h>
int main(){
printf("欢迎来做小学题目\n");
int source=0;
char c;
int i=0;
for(int i=0;i<20;i++){
printf("第%d题\n",i+1);
int op=rand()%10+1;
int ed=rand()%10+1;
if(op < ed) {
int t = op;
op =ed;
ed =t;
}
int s = op %2;
if(s == 0) c='+';
else c='-';
printf(" 请算出:%d %c %d\n",op,c,ed);
int jie;
scanf("%d",&jie);
int daan;
if(s ==0) daan = op +ed;
else daan = op -ed;
if(jie == daan ){
printf("恭喜,答对了,加一分!!!!\n");
source++;
}
else {
printf("错了,正确答案是%d下次继续!!!\n",daan);
}
printf(" 当前分数为%d,总分100分\n",source);
}
printf(" 总分为%d\n",source);
return 0;
}
|