位置:首页 > 软件操作教程 > 编程开发 > C语言 > 问题详情

/*小学生算数*/在C语言的程序中如何编写?

提问人:杨紫红发布时间:2020-11-17

#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;

}

继续查找其他问题的答案?

相关视频回答
回复(0)
返回顶部