template.cpp

来自「杨辉三角形的输出方法设计」· C++ 代码 · 共 35 行

CPP
35
字号
//============================
//程序名称: .cpp
//程序描述: 
//作者: 
//日期:
//版本号: V0.0.1
//============================


#include <iostream> 
#include <iomanip>  
#include <string>
#include <vector>

using namespace std;	  

int main()
{
	for (int n,m = 0; cin >> n;)
	{
		cout << (m++ ? "\n" : "");
		vector<int> b( n, 0), a;
		b[0] = 1;
		for (int i = 1; i <= n; a = b,i++)
		{
			cout << string(3 * n - 3 * i, ' ') + "  1";
			for (int j = 1; j < i; j++)
				cout << setw(6) << (b[j] = a[j - 1] + a[j]);
			cout << "\n";
		}
	}

	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?