【求助】找不到问题出在哪里,随机生成两个数相加,正确率出了问题,有一个错的正确率都变成0.00%
程序代码:
#include <stdio.h> #include <stdlib.h> void main() { int x,y,i,j,k,sum,a=0,b=0; float c; printf("测试题数量:"); scanf("%d",&j); for(i=1;i<=j;i++) { srand((unsigned)time(NULL)); x=rand()%100; y=rand()%100; sum=x+y; printf("第%d题:",i); printf("%d+%d=",x,y); scanf("%d",&k); if(k==sum) { printf("正确!\n"); a++; } else { printf("错误!正确结果应该是%d\n",sum); b++; } } c=a/j; printf("回答正确%d道题,错误%d道题,正确率为%0.2f%%\n",a,b,c*100); }