位置:首頁 > 軟件操作教程 > 編程開發(fā) > C語言 > 問題詳情

/*小學(xué)生算數(shù)*/在C語言的程序中如何編寫?

提問人:楊紫紅發(fā)布時間: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;

}

繼續(xù)查找其他問題的答案?

相關(guān)視頻回答
回復(fù)(0)
返回頂部