编程语言
首页 > 编程语言> > 杨辉三角(C++)

杨辉三角(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;
}

标签:输出,900,int,C++,++,杨辉三角,include
来源: https://blog.csdn.net/the_littlew/article/details/122377281