Pascal triangle 帕斯卡三角形 杨辉三角形 二项式定理
Pascal triangle
等段时间再扯pascal triangle~
先把一年多以前打印杨辉三角形的方法贴出来(简直不认直视,越来越不敢看以前自己写的东东了)
C语言实现:
/***************************************************************Code writer : EOFCode date : 2013.05.16e-mail : jasonleaster@gmail.comCode description :Here is a demo for how to print out the pascal triangle.*****************************************************************/
#include <stdio.h>
#include <stdlib.h>void buildup(int S, int *n);
void putout(int S, int *n);int main()
{int row = 0;int k = 0, m = 0, x = 0, S = 0;printf("Please enter the row number");while(!scanf("%d",&S)){while(getchar() != '\n');printf("please enter again!\n");}int *n = (int *)malloc((S + 1)*(S/2)*sizeof(int));if(!n){printf("malloc failed!\n");return -1;}buildup(S, n);putout(S, n);return 0;
}void buildup(int S, int *n)
{int row , k , m , x , y , a , b;row = k = m = x = y = a = b =0;//initializationfor(m = 0; m < (S+1)*(S/2); m++){n[m] = 0;}for(row = 1; row <= S; row++){m = ((row*(row-1))/2);n[m] = 1;}for(row = 1;row <= S; row++){m = ((row*(row+1))/2) -1;n[m] = 1;}//key methodfor(k = 2; k <= S-1; k++){for(row = (3 + k -2); row <= S; row++){m = ((row*(row-1))/2) - 1 + k;x = m - row;y = m - row + 1;a = ((row*(row+1))/2) - row;b = ((row*(row+1))/2) - 1;if( m != a && m != b){n[m] = n[x] + n[y];}else{n[m] = 1;}}}}void putout(int S, int *n)
{int row , blank , rank , num;row = blank = rank = num = 0;for(row = 1; row <= S; row++){if(row == 1){for(blank = 1; blank <= 4*(S-row); blank++){printf(" ");}}else{for(blank = 1; blank <= (S-row); blank++){printf(" ");}}for(rank = 1; rank <= row; rank++){printf("%d ", n[num]);num++;if(rank == row){printf("\n");}printf(" ");}}
}
摄于二零一四年八月十四日 秋水共长天一色
Pascal triangle 帕斯卡三角形 杨辉三角形 二项式定理相关推荐
- 2017.3.29组合数学学习——帕斯卡三角形、二项式定理
帕斯卡三角形(杨辉三角) n\k 0 1 2 3 4 5 6 7 8 0 1 1 1 1 2 1 2 1 3 1 3 ...
- Pascal's Triangle帕斯卡三角形算法
题目 Pascal's triangle Given numRows, generate the first numRows of Pascal's triangle. For example, gi ...
- 帕斯卡三角形,二项式定理
组合数学少不了二项式,今天来补一补. 0 |1 |2 | 3 |4 |5 |6 |7 |8 0 1 | | | | | ...
- 【离散数学】帕斯卡三角形与二项式定理
C ( n , r ) = n ! r ! ( n − r ) ! C(n,r)=\frac{n!}{r!(n-r)!} C(n
- 帕斯卡三角形(Pascal's triangle)
// The following code is compiled on VC2005 // #include "stdafx.h" /*--------------------- ...
- LeetCode 118 Pascal's Triangle(帕斯卡三角形)(vector)
翻译 给定一个行数字,生成它的帕斯卡三角形.例如,给定numRows = 5, 返回: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1] ] 原文 Given numR ...
- C#,打印漂亮杨辉三角形(帕斯卡三角形)的源代码
杨辉 Blaise Pascal 这是某些程序员看完会哭的代码. 杨辉三角形(Yanghui Triangle),是一种序列数值的三角形几何排列,最早出现于南宋·数学家·杨辉1261年所著的<详 ...
- 帕斯卡三角形 (Pascal)
/*** 帕斯卡三角形 (Pascal)*/ const prompt = require('prompt-sync')() const Pascal = (row, col) => {if ( ...
- java打印10行杨辉三角形_java实现打印杨辉三角形(帕斯卡三角形),打印10行
/** * 打印杨辉三角形(帕斯卡三角形),打印10行 * */ public class Yanghuisanjiao { public static void main(String[] args ...
最新文章
- B1054 求平均值 (20 分)
- feign post 传递空值_听我讲完GET、POST原理,面试官给我倒了杯卡布奇诺
- 七夕赶上服务器架构升级,女朋友的约会怎么办
- 【堆】这是要搞事情啊——取出
- 如何使得窗口最大化?
- es统计有多少个分组_ElasticSearch 分组查询的几个例子
- Java之T分布计算数据的双侧置信区间
- C语言运算符和表达式
- WEB测试和APP测试的区别,全网最齐全的体系梳理,不进来看看?
- 非常好用的桌面壁纸更换软件
- 2015年全国大学生电子设计大赛综合测评题
- SpringBoot-Google二步验证
- 结对编程项目的收获与总结(支持UI背景与背景音乐的刷题器)
- 计算机辅助英语,计算机辅助英语教学
- seo模拟点击软件_关键词快排是什么?SEO快排、刷点击和快排发包原理分析
- 接招吧微软,谷歌大脑跟DeepMind团队合并了!
- java ao层_Java学习过程中的一些记录 DO、DTO、BO、AO、VO、POJO定义 | 酷客365
- 变形金刚3 部分台词
- 我的世界HMCL启动器以及加入服务器步骤
- JavaScript | 正则表达式
热门文章
- windows 查看端口号
- 数睿数据与沙特领先的云平台厂商Virtual Vision达成战略合作!
- Android面试,给正在找工作的安卓攻城师们 ... ...
- PAT乙级_1068 万绿丛中一点红 (20 分)_python
- 3阶魔方阵c语言算法,3阶魔方阵的算法
- 缺陷管理工具--Mantis
- android 保存图片(视频)到相册
- 第6章 歌手详情页开发
- 抽奖动画 - lao虎机抽奖,手把手教你做一个抽奖机软件
- Win11下载速度太慢如何解决?Win11提高下载速度的方法