正序:
/*方法一写顺
for (i = 0; i < 9; i++) {/*边缘为1*
arr2[i][0] = 1;
arr2[i][i] = 1;
}
for (i = 2; i < 10; i++) {
for (j = 1; j < i;j++)
arr2[i][j] = arr2[i - 1][j - 1] + arr2[i - 1][j];
}*/
/*方法二写顺*/
printf("请输入n=");
scanf("%d", &n);
for (i = 0; i < n; i++){
for (j = n; j >= i; j--)
printf("%2c", ' ');
for (j = 0; j<=i; j++) {
if (j == i||j == 0)
arr1[i][j] = 1;
else
arr1[i][j] = arr1[i-1][j-1] + arr1[i-1][j];
printf("%4d", arr1[i][j]);
if (i == j)
printf("\n");
}
}
逆序:
/*逆序*/
for (i = n-2; i >= 0;i--) {
for (j = n; j >= i; j--)
printf("%2c", ' ');
for (j = 0; j <= i; j++) {
printf("%4d", arr1[i][j]);
if (i == j)
printf("\n");
}
}
system("pause");
return 0;
}