6 Order Yang Hui triangle as follows:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
Question: input contains only a positive integer n (1 <= n <= 30), Pascal's triangle represents the number of layers to be output.
Requirements: Pascal's Triangle outputs a corresponding number of layers, each layer between integers separated by a space.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
int main(void)
{
int a[30][30];
int i, j, n;
scanf("%d", &n);
{
int a[30][30];
int i, j, n;
scanf("%d", &n);
for (I = 0; I <n-; I ++)
{
for (J = 0; J <= I; J ++) // Pascal's triangle is a lower triangular matrix
{
IF (J J == I == 0 ||) // first determine not the beginning or end of each line element of
a [I] [J] =. 1;
the else // if it is not the beginning or end element, then it must be an intermediate element
a [i] [j] = a [i- . 1] [J-. 1] + A [I-. 1] [J];
}
}
for (I = 0; I <n-; I ++)
{
for (J = 0; J <= I; J ++)
{
IF (J == 0) // and output of each row is no space
the printf ( "% D", a [I] [J]);
the else
the printf ( "% D", a [I] [J]);
}
the printf ( "\ n-");
}
return 0;
}
{
for (J = 0; J <= I; J ++) // Pascal's triangle is a lower triangular matrix
{
IF (J J == I == 0 ||) // first determine not the beginning or end of each line element of
a [I] [J] =. 1;
the else // if it is not the beginning or end element, then it must be an intermediate element
a [i] [j] = a [i- . 1] [J-. 1] + A [I-. 1] [J];
}
}
for (I = 0; I <n-; I ++)
{
for (J = 0; J <= I; J ++)
{
IF (J == 0) // and output of each row is no space
the printf ( "% D", a [I] [J]);
the else
the printf ( "% D", a [I] [J]);
}
the printf ( "\ n-");
}
return 0;
}
/ * The Internet for a few write Pascal's Triangle code is too complex judgment in this offer streamlined analysis of the code Fool! * /