解决方案
5
把规律找出来就行了
20
仅供参考:
#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
15
1 #include <stdio.h>
2
3 #define WIDE 3
4 int print(int n)
5 {
6 int i;
7 int j;
8
9 for(i = 0; i < n; i++)
10 {
11 for(j = 0; j < n – 1 – i; j++)
12 printf(” “);
13 for(j = 0; j < 2 *i -1; j++)
14 {
15 if(j < i)
16 {
17 printf(“%3d”, (j + 1) * 2 -1);
18 }
19 else
20 {
21 printf(“%3d”, 2 * i – ((j – i + 2) * 2 -1));
22 }
23 }
24 printf(“\n”);
25 }
26 }
2
3 #define WIDE 3
4 int print(int n)
5 {
6 int i;
7 int j;
8
9 for(i = 0; i < n; i++)
10 {
11 for(j = 0; j < n – 1 – i; j++)
12 printf(” “);
13 for(j = 0; j < 2 *i -1; j++)
14 {
15 if(j < i)
16 {
17 printf(“%3d”, (j + 1) * 2 -1);
18 }
19 else
20 {
21 printf(“%3d”, 2 * i – ((j – i + 2) * 2 -1));
22 }
23 }
24 printf(“\n”);
25 }
26 }