可以随机出十以内的加减乘除运算,并判断所答题目的正确与错误个数。第一次发,请多多指教。
代码如下:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int a,x,y,num,ans;
int n,i,j,right,unright,sum;
char b;
srand((unsigned)time(NULL));
i=0;
right=0;unright=0;
scanf("%d",&n);
while(i<n)
{a=rand()%4;
x=rand()%10+1;
y=rand()%10+1;
switch(a)
{
case 1:b='+';num=x+y;break;
case 2:b='-';num=x-y;break;
case 3:b='*';num=x*y;break;
case 0:if(x>y){b='/';num=x/y;}else {b='*';num=x*y;}break;
}
printf("%d %c %d=",x,b,y);
scanf("%d",&ans);
if(ans==num)right++;
else unright++;
i++;
}
printf("共%d,%d道题正确,%d道题错误",i,right,unright);
}
实际操作界面如下: