1089: 杨辉三角
Time Limit: 1 Sec Memory Limit: 128 MBDescription
输出杨辉三角的前N行(N<10)。
Input
输入只有一行,包括1个整数N。(N<10)
Output
输出只有N行,每行输出的数字间用一个空格分开,最后一个数字后面没有空格。
Sample Input
5
Sample Output
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
HINT
Source
#include<iostream>
using namespace std;
int C(int n,int m) //高中排列组合知识
{
int f=1,x=n,f1=1;
while(n>x-m)
{
f*=n--;
}
while(m)
{
f1*=m--;
}
return f/f1;
}
main()
{
int N;
cin>>N;
for(int i=1;i<=N;i++)
{
for(int j=0;j<i;j++)
{
cout<<C(i-1,j);
if(j!=i-1)cout<<' ';
}
cout<<endl;
}
}