杨辉三角
来源:互联网 发布:oa流程数据库设计 编辑:程序博客网 时间:2024/05/29 06:53
杨辉三角
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 41719 Accepted Submission(s): 17481
Problem Description
还记得中学时候学过的杨辉三角吗?具体的定义这里不再描述,你可以参考以下的图形:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
Input
输入数据包含多个测试实例,每个测试实例的输入只包含一个正整数n(1<=n<=30),表示将要输出的杨辉三角的层数。
Output
对应于每一个输入,请输出相应层数的杨辉三角,每一层的整数之间用一个空格隔开,每一个杨辉三角后面加一个空行。
Sample Input
2 3
Sample Output
11 111 11 2 1
数组操作
#include <iostream>#include <string.h>#include <cstdio>using namespace std;int yh[31][31];int main(){ int i,j,n; yh[1][1] = 1; while(cin >> n) { cout << '1' << endl; for(i = 2; i <= n; i++) { for(j = 1; j <= i; j++) { yh[i][j] = yh[i-1][j-1] + yh[i-1][j]; if(j!=1) cout <<' ' <<yh[i][j]; else cout << yh[i][j]; } cout << endl; } cout << endl; } return 0 ;}
0 0
- 杨辉三角/帕斯卡三角
- (尹成)杨辉三角(正三角 倒三角)
- 学习:杨辉三角(帕斯卡三角)
- 杨辉三角
- 杨辉三角
- 杨辉三角
- 杨辉三角算法
- C# 杨辉三角
- 杨辉三角
- 杨辉三角
- 杨辉三角程序
- 打印杨辉三角
- 杨辉三角
- 杨辉三角
- 杨辉三角
- 杨辉三角源代码
- 杨辉三角~~~~~~~~
- 杨辉三角
- 浅析haartraining方法进行人脸检测
- 《unix网络编程》(12)五种I/O模型
- Perforce的使用
- 前端精选文摘:BFC 神奇背后的原理
- 设计模式之原型
- 杨辉三角
- 总结-分治
- 删除多余的Ubuntu内核
- 判断一个数是否是回文数
- linux内核学习(4)_库函数API和C代码嵌入汇运用用系统调用
- 杭电---1106排序
- JavaMail从零开始学习
- 应采儿《天使的城》复出演律师 伶牙俐齿显本色
- 刘诗诗《犀利仁师》鬼马卖萌 丰富表情笑果十足