/*小學(xué)生算數(shù)*/在C語言的程序中如何編寫?
#include"stdio.h"
#include"stdlib.h"
#include"time.h"
int main()
{
while(1)
{
int a,b,c,d,k,type,op;
printf("Please choose the lever!\n1.Easy(0--9)\n2.Hard(10--99)\n");
scanf("%d",&k);
printf("Please choose the type you want!\n");
printf("**********************\n");
printf("*\t1.plus\n*\t2.minus\n*\t3.multiply\n*\t4.divided\n*\t0.exit\n");
printf("**********************\n");
scanf("%d",&type);
if(k==1)
{
a=rand()%10;
b=rand()%10;
}
else
{
a=rand()%100;
b=rand()%100;
}
if(type==0)
{
printf("thank you for using!\n\n");
break;
}
if(type==1)
{
printf("%d+%d=?\n",a,b);
while(1)
{
scanf("%d",&op);
if(a+b==op)
{ printf("Very good! You are rigth! \n\n");
break;
}
else
printf("Sorry,you are wrong!\nPlease again!\n");
}
}
else if(type==2)
{
printf("%d-%d=?\n",a,b);
while(1)
{
scanf("%d",&op);
if(a-b==op)
{ printf("Very good! You are rigth!\n\n");
break;
}
else printf("Sorry,you are wrong!\nPlease again!\n");
}
}
else if(type==3)
{
printf("%d*%d=?\n",a,b);
while(1)
{
scanf("%d",&op);
if(a*b==op)
{
printf("Very good! You are rigth!\n\n");
break;
}
else printf("Sorry,you are wrong!\nPlease again!\n");
}
}
else if(type==4)
{
b=b+1;
printf("%d/%d=? 商幾余幾\n",a,b);
while(1)
{
scanf("%d%d",&c,&d);
if(c==a/b&&d==a%b)
{
printf("Very good! You are rigth!\n\n");
break;
}
else printf("Sorry,you are wrong!\nPlease again!\n");
}
}
}
return 0;
}
點(diǎn)擊加載更多評論>>