第1个回答 2009-11-27
#include <stdio.h>
void main()
{
int a,b,c,c2;
int chances=3;
printf("Input two numbers:");
scanf("%d%d",&a,&b);
c=a+b;
while(chances-->0)
{
printf("%d+%d=",a,b);
scanf("%d",&c2);
if(c==c2)
{
printf("Right!\n");
break;
}
else
{
if(chances==0)
printf("Not correct! You have try three times! Test over.\n");
else
printf("Not Correct! Try again! %d chanecs left!\n",chances);
}
}
getchar();
}
第2个回答 2009-11-27
#include <stdio.h>
void main()
{
int a, b ,sum ,temp , i = 0 ;
printf("Please input two numbers.\n");
scanf("%d %d",&a,&b);
sum = a + b;
printf("%d + %d = ? Please input the answer.\n");
while(i < 3)
{
scanf ("%d",&temp);
if(temp != sum )
printf("not correct! try again!\n");
else
{ printf("Right!\n");break;}
i++;
}
if(temp!=sum)
printf("Not correct! You have try three times! Test over \n");
}
可能 不是 最好的
以我的经验
只能写成这样
第3个回答 2009-11-27
//---------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int ws=0,a,b,c;
srand(time(NULL));
printf("%d+%d=",a=rand()%100,b=rand()%100);
if (scanf("%d",&c),c==a+b) {
printf("Right!\n");
}
else {
do
{
if (++ws==3) puts("Not correct!You have try three times!Test over");
else{
printf(" not correct!try again!\n");
printf("%d+%d=",a,b);
if (scanf("%d",&c),c==a+b) printf("Right!\n");
}
}while (c!=a+b&&ws<3);
}
return 0;
}
//---------------------------------------------------------------------------