首页 > 软件操作教程 > 编程开发 > C语言
题目内容

/*小学生算数*/在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;

}

网友评论(共0条评论)

请自觉遵守互联网相关政策法规,评论内容只代表网友观点!

最新评论

点击加载更多评论>>

软件操作 新人注册送三重礼

已有 22658 名学员学习以下课程通过考试

相关视频试题

最需教育客户端 软件问题一手掌握

去 App Store 免费下载 iOS 客户端