杨辉三角(1)
来源:互联网 发布:编程用什么语言好 编辑:程序博客网 时间:2024/05/16 11:37
#include <iostream>
using namespace std;
#include <iomanip>
void line_first_output(int x)
{
for (int i=0;i<x;i++)
{
cout << " ";
}
}
void FormatOut(int x)
{
cout<< setw(5) << x ;
}
void main()
{
int a[1000];
int n,i;
cin >> n;
for (i=1;i<=n;i++) //输出第i列,1为首列
{
line_first_output(n-i);//输出该行首空格
a[0]=1; //输出头一个
FormatOut(a[0]);
int temp=a[0],result;
for (int j=0;j<i-2;j++) //执行i-2次运算得结果
{
result=a[j+1]+temp;
temp=a[j+1];
a[j+1]=result;
FormatOut(result);
}
if (i>1)
{
a[i-1]=1; //输出后一个
FormatOut(a[i-1]);
}
cout << endl;
}
}
- 杨辉三角(1)
- (尹成)杨辉三角(正三角 倒三角)
- 学习:杨辉三角(帕斯卡三角)
- 杨辉三角<1>
- 算法练习----杨辉三角(1)
- 杨辉三角/帕斯卡三角
- 杨辉三角(C#)
- 杨辉三角(2)
- 杨辉三角(经典)
- 杨辉三角(队列)
- 杨辉三角(生成器)
- 杨辉三角(作业)
- 图形打印(正三角,反三角,菱形)已经杨辉三角10.23
- 别人的杨辉三角(只用1维数组)
- HDU 4927 Series 1(大数+杨辉三角)
- 1、杨辉三角的解决思路
- 杨辉三角(C#版)
- 杨辉三角(C语言)
- first time to write a blog
- 微软PDC10Party北京站活动掠影
- 解决ubuntu下打开windows中的txt文件为乱码的方法
- javascript服务器交互型可编辑表格
- 快速创建表的方法(Oracl,Sqlserver,DB2)
- 杨辉三角(1)
- IM这块肥肉
- JPEG 压缩与解压缩
- first blog
- COM, COM+ and .NET 的区别
- 游戏的简单规则:力量的简单规则
- ubuntu 安装 vsftp服务
- 1023
- Linux基本操作