C语言从入门到项目实战
反正错了,不知道为啥
第220面内容
#include <stdlib.h>
#include <time.h>
int Compute(int x,char op ,int y);
int a,b;
int main(void)
{
int n,k;
char op;
int a,b,ans,yans;
printf("请输入题目数和运算符:\n");
scanf("%d %c", &n, &op);
srand(time(NULL));
while(n--)
{
a=rand()%10+1;
b=rand()%10+1;
ans=Compute(a,op,b);
k=3;
while(k--)
{
printf("%d %op %d = ",a,op,b);
scanf("%d", &yans);
if(yans==ans) break;
else printf("no!\n") ;
}
if(yans!=ans) printf("%d %c %d=%d\n",a,op,b,ans);
else printf("no\n");
return 0;
}
}
int Compute(int x,char op,int y)
{
int res;
switch(op)
{
case '+':res=a+b;break;
case '-':res=a-b;break;
case '*':res=a*b;break;
case '/':res=a/b;break;
}
return res;
}