标签:用c编程实现打印杨辉三角
#include<stdio.h> #include<stdlib.h> #define line 9 //第n行的m个数可表示为 C(n-1,m-1),即为从n-1个不同元素中取m-1个元素的组合数。 //即为:num!/(count!*(num-count)!) "!"为阶乘 int factorial(int z) //阶乘 { int i,count_sum=1; for (i = 1; i <= z; i++) { count_sum *= i; } return count_sum; } int main() { int num, count, kong; //行号-num 数字-count 空格-kong 打印序号-xuhao for (num = 0; num < line; num++) { for (kong = line-num; kong > 0; kong--) printf(" "); for (count = 0; count <= num; count++) printf("%2d ", factorial(num)/ (factorial(count)*factorial(num-count))); printf("\n"); } system("pause"); return 0; }
标签:用c编程实现打印杨辉三角
原文地址:http://10739786.blog.51cto.com/10729786/1702999