第1个回答 2012-04-21
测试结果:
随机2数加法。输入-1结束!
6+7=
13
8+4=
10
Wrong!Please try again.
8+4=
13
Wrong!Please try again.
8+4=
12
1+3=
4
9+5=
-1
代码:
#include "stdio.h"
#include "conio.h"
#include <time.h>
#include <math.h>
#include<stdlib.h>
main()
{
int a,b,sum=0,flag=0;
time_t t;
srand((unsigned)time(&t));
printf("输入2个数求加法,输入-1结束!\n");
while(1)
{
flag=0;
a=rand()%10+1;
b=rand()%10+1;
printf("%d+%d=\n",a,b);
scanf("%d",&sum);
if(sum==-1)
break;
while(flag==0)
{
if(sum==a+b)
flag=1;
else
{
printf("Wrong!Please try again.\n%d+%d=\n",a,b);
scanf("%d",&sum);
}
}
}
getch();
}
第2个回答 2012-04-21
#include<iostream>
#include<time.h>
using namespace std;
int main()
{
int a,b,c;
srand((unsigned) time(NULL));
while(1)
{
a=rand()%10+1;
b=rand()%10+1;
cout<<a<<"*"<<b<<"=";
cin>>c;
if(c==a*b){cout<<"right.\n";break;}
else cout<<"wrong number,try again.\n";
}
return 0;
}
第3个回答 2012-04-21
#include<stdio,h>
#include<time.h>
main()
{
int i,j,k;
srand(time(0));
i=rand()%10+1;
j=rand()%10+1;
printf("%d*%d=",i,j);
while(1)
{
scanf("%d",&k);
if(k==i*j)
{
printf("Right");
break;
}
else
printf("Wrong!Please try again");
}
}
满意请采纳!
第4个回答 2012-04-21
#include<stdlib.h>
#include<stdio.h>
void main()
{
int a,b,c,d;
a=rand()%10+1;
b=rand()%10+1;
c=a*b;
printf("%d*%d=",a,b);
do{
scanf("%d",&d);
if(c==d)
{
printf("Right");
}
if(c!=d)
{
printf("Wrong!Please try again.");
}
}while(c!=d);
}