⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 template.cpp

📁 杨辉三角形的输出方法设计
💻 CPP
字号:
//============================
//程序名称: .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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -