小学数学题

 
先选择运算,包括加法,减法乘法除法四种选项

选择一种运算进入做题,可以选择难易程度,简单是十以内运算,难是一百以内运算

然后进入做题,系统会随机出题


输入答案,系统会判断对错,然后又四个选项。

退出系统会显示做题的数量,与所得的分数

#include<stdlib.h> #include<stdio.h> #include<time.h> int question_get(); int type; void main() { int answer,n,score=0,number=0; loop: printf("请选择要进行测试的题目种类:"); printf(" 1.加法运算 2.减法运算 3.乘法运算 4.除法运算 5.退出运算 "); printf(" 请选择(1-5):"); scanf("%d",&type); while(type>0&&type<6) { int temp; int flag; number=number+1; answer=question_get(); lop:printf("请回答: "); scanf("%d",&temp); if(temp==answer) { printf(" 答案正确 "); score=score+1; } else { printf(" 答案错误 "); } printf("查看答案3,重做请按2,继续请按1,退出请按0 "); scanf("%d",&flag); while(flag!=0&&flag!=1&&flag!=2&&flag!=3) { printf("按其他键无效 "); scanf("%d",&flag); } if(flag==0) { printf("做的题目数量%d ",number); printf("得分%d ",score); break; } else { if(flag==1) goto loop; else { if(flag==2) goto lop; else if(flag==3) { printf("正确答案%d ",answer); goto loop; } } } } } int question_get() { int a,b,c; int amount; loop:if(type==1) { printf("请选择难易程度 "); printf("简单请按0,困难请按1 "); scanf("%d",&amount); while(amount!=0&&amount!=1) { printf("按其他键无效 "); scanf("%d,&amount"); } if(amount==0) { a=rand()%8; b=9-a; b=rand()%b; printf("%d+%d=?",a,b); return(a+b); } else { a=rand()%99; b=100-a; b=rand()%b; printf("%d+%d=?",a,b); return(a+b); } } else if(type==2) { printf("请选择难易程度 "); printf("简单请按0,困难请按1 "); scanf("%d",&amount); while(amount!=0&&amount!=1) { printf("按其他键无效 "); scanf("%d,&amount"); } if(amount==0) { a=rand()%7; b=9-a; b=rand()%b; printf("%d-%d=?",a+b,b); return(a); } else { a=rand()%97; b=99-a; b=rand()%b; printf("%d-%d=?",a+b,b); return(a); } } else if(type==3) { printf("请选择难易程度 "); printf("简单请按0,困难请按1 "); scanf("%d",&amount); while(amount!=0&&amount!=1) { printf("按其他键无效 "); scanf("%d,&amount"); } if(amount==0) { a=rand()%4; b=6-a; b=rand()%b; printf("%d*%d=?",a,b); return(a*b); } else { a=rand()%18; b=20-a; b=rand()%b; printf("%d*%d=?",a,b); return(a*b); } } else if(type==4) { printf("请选择难易程度 "); printf("简单请按0,困难请按1 "); scanf("%d",&amount); while(amount!=0&&amount!=1) { printf("按其他键无效 "); scanf("%d,&amount"); } if(amount==0) { a=rand()%4; b=6-a; b=1+rand()%b; printf("%d/%d=?",a*b,b); return(a); } else { a=rand()%18; b=20-a; b=1+rand()%b; printf("%d/%d=?",a*b,b); return(a); } } while(type==0&&type>5) { printf("输入错误 "); printf("请输入1-5 "); scanf("%d",&type); goto loop; } }

  

原文地址:https://www.cnblogs.com/siwen/p/5268067.html