HDOJ2032(杨辉三角)

来源:互联网 发布:淘宝four loko是真的嘛 编辑:程序博客网 时间:2024/05/20 00:11
#include <iostream> 
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <math.h>


using namespace std;
#define N 110


int a[N][N];


void yh()
{
for (int i = 1; i <= 30; i++)
for (int j = 1; j <= i; j++)
{
if (j == 1 || j == i) a[i][j] = 1;
else a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
}
}


int main()
{
yh();
int n;
while (cin >> n)
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j < i; j++)
cout << a[i][j] << " ";
cout << 1 << endl;
}
cout << endl;
}
}
原创粉丝点击