Ninth job Pascal's Triangle

#include <stdio.h>
int main(void)
{
int i, j, k, n=0;
int a[12][12];
while(n<=0||n>=11){
printf("请输入要打印的行数:");
scanf("%d",&n);
}
printf("%d行杨辉三角如下:\n",n);
for(i=1;i<=n;i++)
a[i][1] = a[i][i] = 1;
for(i=3;i<=n;i++)
for(j=2;j<=i-1;j++)
a[i][j]=a[i-1][j-1]+a[i-1][j];
for(i=1;i<=n;i++){
for(k=1;k<=n-i;k++)
printf(" ");
for(j=1;j<=i;j++)
printf("%6d",a[i][j]);
printf("\n");
}
printf("\n");
}

 

The problem involves knowledge is the definition and application of two-dimensional arrays and algorithms on Pascal's Triangle. Doing it in the definition and application of two-dimensional array of less skilled, so do for a long time.
 

Guess you like

Origin www.cnblogs.com/LXH614/p/11006367.html