- int yang(int n, int k)
- {
- if(k==0 || k==n)
- return 1;
- else
- return yang(n-1, k) + yang(n-1, k-1);
- }
- int main(int argc, char *argv[])
- {
- int n;
- int i, j;
- while(scanf("%d", &n) != EOF)
- {
- for(i = 1; i < n; i++)
- for(j = 0; j <= i; j++){
- printf("%d", yang(i, j));
- if(j < i)
- printf(" ");
- else
- printf("\n");
- }
- }
- return 0;
- }[code]int a[100][100];
- int main(int argc, char *argv[])
- {
- int i, j, n;
- while(scanf("%d", &n) != EOF)
- {
- a[0][0] = 1;
- a[0][1] = 1;
- printf("%d %d\n", a[0][0], a[0][1]);
- for(i = 1; i < n-1; i++)
- {
- a[i][0] = 1;
- printf("%d ", a[i][0]);
- for(j = 1; j <= i; j++)
- {
- a[i][j] = a[i-1][j] + a[i-1][j-1];
- printf("%d ", a[i][j]);
- }
- a[i][j] = 1;
- printf("%d\n", a[i][j]);
- }
- }
- return 0;
- }
复制代码 [/code] |