c language Ninth jobs

t

Title: Triangle output.

/ * * Pascal's Triangle /

#include <stdio.h>
void main ()
{
int I, J, K, n-= 0;
/ * define a two-dimensional array A [I] [J] * /
int A [12 is] [12 is];
/ * Control the number of lines for printing * /
the while (n-<= 0 || n-> =. 11) {
the printf ( "Please enter the number of lines to be printed:");
Scanf ( "% D", & n-);
}
the printf ( "% D row Pascal's triangle follows: \ n-", n-);
for (I = 1; I <= n-; I ++)
/ * number on both sides so that it is 1, because the cycle from the beginning to 1, that a [i] [1 ] The first number * /
A [I] [. 1] = A [I] [I] =. 1;
for (I =. 3; I <= n-; I ++)
for (J = 2; J <= I- . 1; J ++)
/ * in addition to the number of sides are equal to two the number of and * /
a [I] [J] = a [I-. 1] [J-. 1] + a [I-. 1] [J] ;
for (I =. 1; I <= n-; I ++) {
for (K =. 1; K <= Ni; K ++)
/ * line digital intermediate output leave room to make clearer * /
the printf ( "");
for (J =. 1; J <= I; J ++)
the printf ( "% 6D", A [I] [J]);
/ * Wrap * /
the printf ( "\ n-");
}
printf("\n");
}

Experiences: this job, I understand the language used to write c Triangle, and also have a better understanding of the definition and application of two-dimensional array, that is, at the time of writing there are still difficulties, as circulated by the for statement and input error occurs when output. When a program is to write long, indented to do in this regard is not as beautiful as the other students, always feel confused, sometimes further improved when the program errors.

Guess you like

Origin www.cnblogs.com/msjzyp321/p/11006116.html