杨辉三角(C++)

#include<iostream>
#include<cstdio>

#include <iomanip>
using namespace std;


int b[900][900]= {0};

int main()
{
	int n;
	cin >> n;
	b[0][0] = 1;
	for (int i = 1; i < n; i++)// 控制输出n行
	{
		for (int j = 1; j < i; j++)//控制一行输出几个
		{
			b[i][j] = b[i-1][j-1]+b[i-1][j];//全是1的单独输出,用函数写输出有规律的
			
		}
		b[i][0] = 1;
		b[i][i] = 1;
	}
	for (int k = 0; k < n; k++)
	{
		for (int j = 0; j <= k; j++)
			cout << b[k][j]<<" ";
		cout << endl;
	}
	return 0;
}

上一篇:OCP 062【中文】考试题库(cuug内部资料)第9题


下一篇:AcWing 900. 整数划分