有两个很有意思的编程问题,请高手用C++帮我编一下.小弟感激不尽啊...

问题:1、编写一段程序,帮助一所小学的学生学习乘法。用rand 生成两个一位整数。程序利用这两个整数输出如下的问题:How much is 6 times7?
然后由学生来计算答案。程序将检查学生的答案。如果正确,输出“very good!”,并且提出另外一个问题。如果答案错误,输出“No, please try again”,让学生重新计算这个问题,直到答案正确为止。
2、用递归方法求n 阶勒让德多项式的值,递归公式为:
1 (n=0)
pn(x)= x (n=1)
((2n-1)*x*pn-1(x)-(n-1)*pn-2(x))/n (n>1)
一定要用C++哦....

问题1用QBASIC我可以编.
cls
randomize timer
a=rnd*10
b=rnd*10
c=a+b
print a;"+";b;"=?"
input d
if c=d then print"very good!":end else
do while c<>d
print "try again"
input d
loop
end
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-04-20
问题1用c++
#include <iostream>
#include <time.h>
using namespace std;
void main()
{
srand( (int)time( 0 ) );
int a[2];
for(int i=0;i<2;i++)
a[i]=rand()%10;
int b;
int c=1;
int d;

while (c==1)
{
cout<<"how much is "<<a[0]<<" times "<<a[1]<<"?"<<endl;
cin>>d;
b=a[0]*a[1];
if(d!=b)
{
cout<<"No!"<<endl;
cout<<"(1) try again!"<<endl;
cout<<"(2) answer!"<<endl;
cin>>c;
}
else
{
cout<<"very good!"<<endl;
c=2;
}
}
cout<<"answer is:"<<b<<endl;
}
相似回答
大家正在搜