Job Nine: Pascal's Triangle

Pascal's Triangle

 

#include <stdio.h>
int main ()
{
int I, J, n;
int A [100] [100];
the printf ( "Enter n rows:"); / * number of rows in Pascal's triangle * input /
Scanf ( "% D", & n-);
A [0] [0] =. 1; / * a first row, first column *. 1 /
for (I = 0; I <n-; I ++)
{
A [I] [0 ] = 1; / * * a first row are all 1 /
for (J = 0; J <= I / 2; J ++) {
iF (J == 0) / * determines whether the first column * /
A [I ] [J] = A [0] [0];
the else
A [I] [J] = A [. 1-I] [J-. 1] + A [. 1-I] [J]; / * is greater than a second row element * /
a [I] [ij of] = a [I] [J];
}
}
for (I = 0; I <n-; I ++) {
for (J = 0; J <Ni-. 1; J ++)
the printf ( "\ T");
for (J = 0; J <= I; J ++)
the printf ( "\ T% D \ T", A [I] [J]); / * output Pascal triangle * /
the printf ( " \ n-");
}
return 0;
}

Thoughts: the more backward the more difficult procedure, every time I get programmed not get impatient, or more requires some patience, multi-operation, when the program can not get out, under the temper-resistant, multi-inspection check to see if an error where

Guess you like

Origin www.cnblogs.com/xzy123/p/123zy.html
Recommended