标签:get while amp \n += add 分享 ++ scan
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],b[10],d[10],c[10],num=0,result,add=0;
float val;
char fa[5]={‘+‘,‘-‘,‘*‘,‘/‘};
while(1)
{
d[num]=abs(rand())%4;
while(1)
{
c[num]=-1;
a[num]=abs(rand())%100;
b[num]=abs(rand())%100;
if(d[num]==0) c[num]=a[num]+b[num];
else if(d[num]==1) c[num]=a[num]-b[num];
else if(d[num]==2) c[num]=a[num]*b[num];
else if(d[num]==3)
{
if(b[num]>0)val=1.0*a[num]/b[num];
}
if(d[num]<=2)
{
if(c[num]>=0 && c[num]<=100) break;
}
else
{
if(a[num]==int(val)*b[num])
{c[num]=val; break;}
}
}
num++;
if(num==10) break;
}
/* 回答 */
num=0;
while(1)
{
printf("%d %c %d= ",a[num],fa[d[num]],b[num]);
scanf("%d",&result);
if(result==c[num])
{
printf("回答正确!\n");
add+=10;
}
else
printf("错误,正确答案: %d\n",c[num]);
num++;
if(num==10) break;
}
printf("\n得分:%d\n",add);
getch();
}
标签:get while amp \n += add 分享 ++ scan
原文地址:https://www.cnblogs.com/ljw199106m/p/9886034.html