码迷,mamicode.com
首页 > 编程语言 > 详细

c语言实现杨辉三角形

时间:2018-03-01 23:38:09      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:highlight   ++   sharp   gpo   include   输出   sha   else   arp   

#include <stdio.h>

int main(void)
{
	int a[9][9]={};
	int i,j;
	for(i=0;i<9;i++){
		for(j=0;j<=i;j++){
			a[i][j] = 0;
			if(j==0 || i==j){
				a[i][j] = 1; 
			}else{
				a[i][j] = a[i-1][j-1]+a[i-1][j];
			}
			printf("%2d ",a[i][j]);
		}
		printf("\n");
	}
	
	return 0;
}

输出结果 

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

 

c语言实现杨辉三角形

标签:highlight   ++   sharp   gpo   include   输出   sha   else   arp   

原文地址:https://www.cnblogs.com/wanglijun/p/8490688.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!