用C语言编程

程序首先随机产生两个1~10之间的正整数,在屏幕上打印出问题,例如:
6*7=
然后让学生输入答案。程序检查学生输入的答案是否正确。若正确,则打印“Right”,然后问下一个问题;否则打印“Wrong!Please try again.”,然后提示学生重做,直到答对为止。
#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);
}
该如何修改?

#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); //主要是等于号和赋值符号之间的相互混淆
}

亲,满意就采纳哦!!
温馨提示:答案为网友推荐,仅供参考
第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);
}
相似回答