下列程序的执行结果是什么?
#include “stdio.h”
#include “stdlib.h”
#include “time.h”
void main()
{int a, b, answer, result,error, score, i, op;
srand(time(NULL));
error=0;
score=0;
for(i=0;i<10;i++)
{
a=rand()%10+1;
b=rand()%10+1;
op=rand()%4+1;
switch(op)
{
case 1:
printf(“%d+%d=”,a,b);
result=a+b;
break;
case 2:
printf(“%d-%d=”,a,b);
result = a – b;
break;
case 3:
printf(“%d * %d=”,a,b);
result=a*b;
break;
case 4:
if(b!=0)
{
printf(“%d/%d=”,a,b);
result=a/b;/*注意这里是整数除法运算,结果为整型*/
}
else
{ printf(“Division by zero!\n”); }
break;
default:
printf(“Unknown operator!\n”);
break;
}
scanf(“%d”,&answer);
if(result==answer)
{printf(“Rright!\n”); score = score + 10;}
else
{printf(“Not correct!\n”); error++;}
}
printf(“score = %d, error numbers = %d\n”, score, error);
}
程序的执行结果是:
随机产生10道加减乘除运算,输入每道题答案,正确加十分,错误则记录错误的题数。
暂无评论内容