C 练习实例61 - 杨辉三角形

C 语言教程 · 2019-02-22 09:13:12

题目:打印出杨辉三角形(要求打印出10行)。

程序分析:

结构如下所示:

1
1    1
1    2    1
1    3    3    1
1    4    6    4    1

实例

// Created by www.codercto.com on 15/11/9. // Copyright © 2015年 码农教程. All rights reserved. // #include <stdio.h> int main() { int i,j; int a[10][10]; printf("\n"); for(i=0;i<10;i++) { a[i][0]=1; a[i][i]=1; } for(i=2;i<10;i++) for(j=1;j<i;j++) a[i][j]=a[i-1][j-1]+a[i-1][j]; for(i=0;i<10;i++) { for(j=0;j<=i;j++) printf("%5d",a[i][j]); printf("\n"); } }

以上代码执行输出结果为:

1
1    1
1    2    1
1    3    3    1
1    4    6    4    1
1    5   10   10    5    1
1    6   15   20   15    6    1
1    7   21   35   35   21    7    1
1    8   28   56   70   56   28    8    1
1    9   36   84  126  126   84   36    9    1

点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html

查看所有标签

Computational Advertising

Computational Advertising

by Kushal Dave、Vasudeva Varma / Now Publishers Inc / 2014

Computational Advertising (CA), popularly known as online advertising or Web advertising, refers to finding the most relevant ads matching a particular context on the Web. The context depends on the t......一起来看看 《Computational Advertising》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

MD5 加密
MD5 加密

MD5 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器