當前位置:編程學習大全網 - 編程語言 - c語言的作業,要求能在vc上編譯 面向小學1~2年級,隨機選擇兩個整數和加減法形成算式要求學生解答

c語言的作業,要求能在vc上編譯 面向小學1~2年級,隨機選擇兩個整數和加減法形成算式要求學生解答

#include?<stdio.h>

#include?<stdlib.h>

#include?<time.h>

int?score=0;

int?count=1;

void?func()

{

int?answer=1;

int?a,b,c,opration,input;

while(1)

{

a=rand()%49+1;

b=rand()%49+1;

opration=rand()%2;?//0:+1:-

if(opration==0)

{

if(a+b>50)

{

continue;

}

else

{

c=a+b;

break;

}

}

else

{

if(a-b<0)

{

int?t=a;

a=b;

b=t;

}

c=a-b;

break;

}

}

while(answer<=3)

{

if(opration==0)

{

printf("\n第%d題:?%d?+?%d?=?",count,a,b);

}

else

{

printf("\n第%d題:?%d?-?%d?=?",count,a,b);

}

fflush(stdin);

scanf("%d",&input);

if(c==input)

{

switch(answer)

{

case?1:

score+=10;

break;

case?2:

score+=7;

break;

case?3:

score+=5;

break;

}

count++;

return;

}

else

{

if(answer==3)

{

printf("\n三次回答錯誤,?正確答案為:?%d\n",c);

count++;

return;?

}

printf("\n錯誤,?請重新輸入!\n");

answer++;

}

}

}

int?main()

{

srand((unsigned)time(0));

int?i;

for(i=0;i<10;i++)

{

func();

}

printf("\n\n妳的成績為:?%d",score);

switch(score/10)

{

case?10:

case?9:

printf("?SMART");

break;

case?8:

printf("?GOOD");

break;

case?7:

printf("?OK");

break;

case?6:

printf("?PASS");

break;

default:

printf("?AGAIN");

break;

}

return?0;

}

  • 上一篇:HY高速可編程控制器
  • 下一篇:東風天錦洗掃車配置 東風國六天錦洗掃車介紹
  • copyright 2024編程學習大全網