如题所述
第1个回答 2018-10-21
#include <stdio.h> #include <time.h> void main() { int num,mark=0,i; int num1,num2,sum,n; scanf("%d",&num); srand((unsigned) time(NULL)); for(i=0;i<num;i++) { num1=rand()%100; num2=rand()%100; n=rand()%4; switch(n) { case 0 : { printf("%d+%d=\n",num1,num2); printf("输入答案\n"); scanf("%d",&sum); if(sum==num1+num2) { printf("right!\n"); mark++; } else printf("wrong!\n"); } break; case 1 : { printf("%d÷%d=\n",num1,num2); printf("输入答案\n"); scanf("%d",&sum); if(sum==num1/num2) { printf("right!\n"); mark++; } else printf("wrong!\n"); } break; case 2 : { printf("%d-%d=\n",num1,num2); printf("输入答案\n"); scanf("%d",&sum); if(sum==num1-num2) { printf("right!\n"); mark++; } else printf("wrong!\n"); } break; case 3 : { printf("%d*%d=\n",num1,num2); printf("输入答案\n"); scanf("%d",&sum); if(sum==num1*num2) { printf("right!\n"); mark++; } else printf("wrong!\n"); } break; } } printf("\n正确个数为%d\n",mark); }本回答被提问者和网友采纳