user-0 提问: 杨辉三角形

回复:
user: user-1
content: 仅供参考：#include <stdio.h> #define MAXN 10 unsigned __int64 y[MAXN][MAXN]; int i,j; char s[60]; void main() {     printf("%30s\n","1  ");     printf("%33s\n","1     1  ");     y[1][0]=1ui64;y[1][1]=1ui64;     for (i=2;i<MAXN;i++) {         y[i][0]=1ui64;sprintf(s,"1  ");         for (j=1;j<=i-1;j++) {             y[i][j]=y[i-1][j-1]+y[i-1][j];             sprintf(s,"%s   %-3I64u",s,y[i][j]);         }         y[i][i]=1ui64;sprintf(s,"%s   1  ",s);         printf("%*s\n",30+i*3,s);     } } //                           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  //按如下格式打印杨辉三角形的前MAXN行。 //  1 //  1 1 //  1 2 1 //  1 3 3 1 //  1 4 6 4 1 //  1 5 10 10 5 1 #include <stdio.h> #define MAXN 68 unsigned __int64 y[MAXN][MAXN]; int i,j; void main() {     printf("1\n");     printf("1 1\n");     y[1][0]=1ui64;y[1][1]=1ui64;     for (i=2;i<MAXN;i++) {         y[i][0]=1ui64;printf("1 ");         for (j=1;j<=i-1;j++) {             y[i][j]=y[i-1][j-1]+y[i-1][j];             printf("%I64u ",y[i][j]);         }         y[i][i]=1ui64;printf("1\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 //... //1 67 2211 47905 766480 9657648 99795696 869648208 6522361560 42757703560 247994680648 1285063345176 5996962277488 25371763481680 97862516286480 345780890878896 1123787895356412 3371363686069236 9364899127970100 24151581961607100 57963796707857040 129728497393775280 271250494550621040 530707489338171600 972963730453314600 1673497616379701112 2703342303382594104 4105075349580976232 5864393356544251760 7886597962249166160 9989690752182277136 11923179284862717872 13413576695470557606 14226520737620288370 14226520737620288370 13413576695470557606 11923179284862717872 9989690752182277136 7886597962249166160 5864393356544251760 4105075349580976232 2703342303382594104 1673497616379701112 972963730453314600 530707489338171600 271250494550621040 129728497393775280 57963796707857040 24151581961607100 9364899127970100 3371363686069236 1123787895356412 345780890878896 97862516286480 25371763481680 5996962277488 1285063345176 247994680648 42757703560 6522361560 869648208 99795696 9657648 766480 47905 2211 67 1

user: user-2
content: 程序从main()函数开始执行的，但你主函数没初始化变量x就调用了，所以程序不能顺利的执行。

user: user-3
content: 呃 居然还真有人拿组合数填杨辉三角的

user: user-4
content: 请问你的x等于多少？？没有任何初始化就直接判断，怎么可能会出来结果呢！楼主写程序要细心点啊！

user: user-5
content: 参看一下吧   #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; }

user: user-6
content: 不知道你在写什么。 main函数里也没初始化x,也没scanf，直接对x判断，当然不对了 参考下别人写的：http://www.2cto.com/kf/201510/445957.html

user: user-7
content: 你 main 函数中的 x 没有初始化就使用了 你 factorial 函数中的 i 也没有初始化就使用