#include <stdio.h> #include <time.h> int main() { int a,i,n,o,x,y,z; printf("请输入题目数:"); scanf("%d",&n); while(n--) { srand((unsigned)time(NULL)); x=rand()%10+1; y=rand()%10+1; o=rand()%4; switch(o) { case 0: printf("%d + %d = ",x,y); a=x+y; break; case 1: printf("%d - %d = ",x,y); a=x-y; break; case 2: printf("%d * %d = ",x,y); a=x*y; break; case 3: printf("%d / %d = ",x,y); a=x/y; break; } scanf("%d",&z); i=2; while(z!=a&&i--) { printf("答案错误,输入正确后才可获取下一题!\n"); scanf("%d",&z); } if(z==a) printf("答案正确!\n"); } return 0; }