user-0 提问: 求问各位大佬一道C语言打印杨辉三角的题

回复:
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: #include <stdio.h> void yhsj(int n) {     int i, j;      int a[n][n];     if(n <= 1){         printf("%d",1);         return;     }      a[0][0]=1;     a[1][0]=a[1][1]=1;     for(i=2;i<n;i++){         a[i][0]=1;         a[i][i]=1;         for(j=1;j<i;j++){             a[i][j]=a[i-1][j-1]+a[i-1][j];         }     }      for(i=0;i<n;i++){         for(j=0;j<n;j++){             if(i>=j){                 if(j==0){                     printf("%d",a[i][j]);                 }                 else printf(" %d",a[i][j]);             }         }         printf("\n");     }  }   int main() {     int n;     while(scanf("%d",&n)!=EOF){         yhsj(n);         printf("\n");     }      return 0; } 精简了一些逻辑，可以参考一下； Linux下输入ctrl+d；windows下输入ctrl+z终止输入，退出程序；  建议yhsj函数使用动态申请空间，而不用静态可变数组。C语言不支持动态数组（编译没问题，运行可能会因为溢出导致程序不能正常运行），但是C++是支持的。