四则运算升级版
#include<stdio.h> main() { int a,b,i=0,c,d,r=0,W; printf("请输入题目总数:"); scanf("%d",&W); while(i<W) { i++; srand(time()); a=rand()%10+1; b=rand()%10+1; c=rand()%6+1; switch(c) { case 1:printf("第%d题:",i); printf("%d+%d=",a,b); scanf("%d",&d); if(d!=a+b) printf("回答错误!正确答案为%d\n\n",a+b); else r++; break; case 2:printf("第%d题:",i); printf("%d-%d=",a,b); scanf("%d",&d); if(d!=a-b) printf("回答错误!正确答案为%d\n\n",a-b); else r++; break; case 3:printf("第%d题:",i); printf("%d*%d=",a,b); scanf("%d",&d); if(d!=a*b) printf("回答错误!正确答案为%d\n\n",a*b); else r++; break; case 4:printf("第%d题:",i); printf("%d/%d=",a,b); scanf("%d",&d); if(d!=a/b) printf("回答错误!正确答案为%d\n\n",a/b); else r++; break; } } printf("\n\n一共%d题,共答对%d题\n",W,r); }
测试结果:
总结:
除法方面只能算出整形的商,没法以分数形式输入商!