Note: * = n次方 --- nCr= n!/(r!(n-r)!) (100分)

Q

QNelson

Unregistered / Unconfirmed
GUEST, unregistred user!
本人不知完何做这条program,请各位pascal高手帮忙,thank you very much



Note: * = n次方


A pascal triangle is a triangle shaped set of integers which represents the coefficients of the binomial (a+b)*.Each number in the triangle can be calculated by

nCr= n!/(r!(n-r)!)

An example triangle consist of 5 rows is show as follows:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Note that both n and r in the above formula start from 0.
Write a pascal program to input the number of row required and then general the corresponding pascal triangle as the output of your program.
In addition, your program must:
Contain at least two user-define functions, one for the factorial function n! and the other for nCr




 
不就是写一个阶乘函数和一个组合函数用以实现杨辉三角吗:
function Fact(n: Integer): Integer
//阶乘函数
var
i: Integer;
begin
if n <> 0 then
begin
Result := n;
for i := 2 to n do
Result := Result * Result;
end
else
Result := 1;
end;

function nCr(n, r: Integer): Integer
//组合函数
begin
Result := Fact(n) div (Fact(r) * Fact(n - r));
end;
 
我建议你涉及到算法的问题,如果不是很难,尽量自己研究,这对你来说很重要
 
yfdciom 说得有道理:)
 
帕斯卡三角形么?
bata作得不错,不过也太老掉牙了吧?
 
顶部