#include "stdio.h" #include"windows.h" int right=0,wrong=0; void add() { int a,b,c; a=rand()%100; b=rand()%100; printf("请回答:%d+%d=",a,b); scanf("%d",&c); if(a+b!=c){printf("错误 ");wrong++;} else {printf("正确 ");right++;} } void minu() { int a,b,c; a=rand()%100; b=rand()%100; printf("请回答:%d-%d=",a,b); scanf("%d",&c); if(a-b!=c){printf("错误 ");wrong++;} else {printf("正确 ");right++;} } void mul() { int a,b,c; a=rand()%100; b=rand()%100; printf("请回答:%d*%d=",a,b); scanf("%d",&c); if(a*b!=c){printf("错误 ");wrong++;} else {printf("正确 ");right++;} } void di() { int a,b,c; a=rand()%100; b=rand()%100; printf("请回答:%d/%d=",a,b); scanf("%d",&c); if(a/b!=c){printf("错误 ");wrong++;} else {printf("正确 ");right++;} } void main() { int choise,con=0; printf(" 随机数的四则运算 "); system("pause"); system("cls"); while(1) { printf(" 请选择: 加(输入1) 减(输入2) 乘(输入3) 除(输入4) "); if(con==0)scanf("%d",&choise); switch(choise) { case 1:add();break; case 2:minu();break; case 3:mul();break; case 4:di();break; } printf("是否继续或者重新选择运算或者退出程序? 继续(输入1),重新(输入2),退出(输入3)"); scanf("%d",&con); if(con==1)con=1; if(con==2)con=0; if(con==3)break; } printf("您总做了%d个题,正确%d道,错误%d道! ",right+wrong,right,wrong); system("pause"); }