四则运算:给小学生随机出100道加减乘除题,判断对错并且要计算得数。
#include <stdio.h>
#include <stdlib.h>
int main() {
int x,y,z,a,score=0,i;
//定义2个随机变量,两个结果,一个分数
char symbol;
//定义一个运算符:+-*/
srand((unsigned)time(NULL)) ;
// 随机数发生器的初始化函数
for(i=0;i<=100;i++)
{
x=rand()%100;
y=rand()%100;
symbol=rand()%4;
printf("%d",x);
switch(symbol)
{
case 0:
printf("+");
z=x+y;
break;
case 1:
printf("-");
z=x-y;
break;
case 2:
printf("*");
z=x*y;
break;
case 3:
printf("/");
z=x/y;
break;
default:
printf("ERROR
");
}
printf("%d
",y);
scanf("%d",&a);
if(a==z)
{
printf("right
");
score++;}
else
printf("wrong
");
}
return 0;
}