HDU2032 杨辉三角
来源:互联网 发布:python dateutil 编辑:程序博客网 时间:2024/06/05 15:37
问题链接:HDU2032 杨辉三角。这是一个入门训练题,用C语言编写程序。
问题简述:参见上述链接。
问题分析:这里给出两个版本的程序,分别用一维数组和二维数组来存储杨辉三角。使用二维数组存储杨辉三角,可以实现一次计算多次使用。使用一维数组存储杨辉三角,需要更高的技巧。编程时候,需要注意空格输出的条件。
程序说明:(略)。
有关杨辉三角程序,参见:I00001杨辉三角。
AC的C语言程序如下(使用二维数组的版本):
/* HDU2032 杨辉三角 */#include <stdio.h>int pascal[30+1][30+1];// 使用二维数组的杨辉三角程序void pascalgo(int n){ int i, j; for(i=0; i<n; i++) for(j=0; j<=i; j++) if(j == 0 || j == i) pascal[i][j] = 1; else pascal[i][j] = pascal[i-1][j] +pascal[i-1][j-1];}void pascalprint(int n){ int i, j; for(i=0; i<n; i++) { for(j=0; j<=i; j++) { if(j != 0) printf(" "); printf("%d", pascal[i][j]); } printf("\n"); }}int main(void){ int n; pascalgo(30); while(scanf("%d", &n) != EOF) { pascalprint(n); printf("\n"); } return 0;}
AC的C语言程序如下(使用一维数组的版本):
/* HDU2032 杨辉三角 */#include <stdio.h>int pascal[30+1];// 使用一维数组的杨辉三角程序void pascalgo(int n){ int i, j; for(i=0; i<n; i++) { for(j=i; j>=0; j--) { if(j == i || j == 0) pascal[j] = 1; else pascal[j] += pascal[j-1]; if(j != i) printf(" "); printf("%d", pascal[j]); } printf("\n"); }}int main(void){ int n; while(scanf("%d", &n) != EOF) { pascalgo(n); printf("\n"); } return 0;}
1 0
- hdu2032 杨辉三角
- hdu2032 杨辉三角
- hdu2032 杨辉三角
- HDU2032 杨辉三角
- HDU2032---杨辉三角
- 杨辉三角hdu2032
- HDU2032 杨辉三角
- 杨辉三角 HDU2032
- HDU2032杨辉三角
- hdu2032 杨辉三角
- HDU2032杨辉三角
- HDU2032 杨辉三角
- hdu2032杨辉三角
- HDU2032 杨辉三角
- hdu2032—— 杨辉三角
- HDU2032(杨辉三角预处理)
- hdu2032 杨辉三角(C语言)
- HDU2032
- Oracle分页
- Cocos2d-x开发系列 交叉开发模式二 初始化和重启
- MVP模式在Android项目中的使用
- Android中Button文字不能铺满解决方法
- 同一个页面,多个script标签中Javascript执行问题
- HDU2032 杨辉三角
- js实现多图上传和预览(包含表单上传、ajax上传)
- SDUTACM打字系统初体验
- 二维码的生成与识别
- mac安装pip
- Win7 IIS建站
- Java(Android)中线程池的使用
- 海量数据处理专题
- Get Java System Properties and Get OS Envs