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

查看所有标签

Boolean Reasoning

Boolean Reasoning

Brown, Frank Markham / 2003-4 / $ 19.15

A systematic treatment of Boolean reasoning, this concise, newly revised edition combines the works of early logicians with recent investigations, including previously unpublished research results. Th......一起来看看 《Boolean Reasoning》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具