#include
#include
void main()
{
char op;
int a, b, c;
while (1)
{
printf("请输入运算符:\n->");
scanf("%c", &op);
fflush(stdin);
if (op != '+' && op != '-' && op != '*' && op != '/')
{
printf("请输入正确的运算符\n");
continue;
}
srand((unsigned)time(NULL));
a = rand() % 100;
b = rand() % 100;
printf("请计算:\n%d %c %d = ", a, op, b);
scanf("%d", &c);
fflush(stdin);
switch(op)
{
case '+':
if(c == a + b)
printf("运算正确,好棒!\n");
else
printf("运算错误!\n");
break;
case '-':
if(c == a - b)
printf("运算正确,好棒!\n");
else
printf("运算错误!\n");
break;
case '*':
if(c == a * b)
printf("运算正确,好棒!\n");
else
printf("运算错误!\n");
break;
case '/':
if(c == a / b)
printf("运算正确,好棒!\n");
else
printf("运算错误!\n");
break;
}
printf("是否继续? 是-y, 否-n:\n->");
if (getchar() == 'n')
return;
}
}
#include
#include
#include
void main()
{
int x,y,sum;
char ch;
printf("请输入运算符:");
scanf("%c",&ch);
srand(time(0));
x=rand()%101;
y=rand()%101;
if(ch=='+')
{
printf("%d+%d=",x,y);
scanf("%d",&sum);
if(sum==(x+y))
printf("运算正确,好棒!");//后面的减法、乘法、除法用同样的方法就可以了,我不给你写了。
else printf("回答错误,加油啊!");
}
}
简单