标签:
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int i;
void main()
{
char s;
double deshu,daan;
srand(time(0));
int a=rand()%1000+1;
int b=rand()%1000+1;
int c=rand()%4+1;
switch(c)
{
case 1: s=‘+‘;break;
case 2: s=‘-‘;break;
case 3: s=‘*‘;break;
case 4: s=‘/‘;break;
}
printf("\n%d%c%d= ",a,s,b);
scanf("%lf",&deshu);
if(c==1)
{
daan=a+b;
if(deshu==daan) printf("正确!\n");
else printf("答错了…答案是 %g\n",daan);
}
if(c==2)
{
daan=a-b;
if(deshu==daan) printf("正确!\n");
else printf("答错了…答案是 %g\n",daan);
}
if(c==3)
{
daan=a*b;
if(deshu==daan) printf("正确!\n");
else printf("答错了…答案是 %g\n",daan);
}
if(c==4)
{
daan=a/b;
if(deshu==daan) printf("正确!\n");
else printf("答错了…答案是 %f\n",daan);
}
i++; //题目数加1
if(i==10) exit(0); //一共10道题
else main(); //返回继续执行
}
标签:
原文地址:http://www.cnblogs.com/kookkook/p/4384104.html