/*********************************************************** * This small program displays a Pascal's triangle * * up to 15 lines. * * -------------------------------------------------------- * * SAMPLE RUN: * * * * How many lines: 10 * * * * p 0 1 2 3 4 5 6 7 8 9 * * n * * ----------------------------------------------------- * * 0 -- 1 * * 1 -- 1 1 * * 2 -- 1 2 1 * * 3 -- 1 3 3 1 * * 4 -- 1 4 6 4 1 * * 5 -- 1 5 10 10 5 1 * * 6 -- 1 6 15 20 15 6 1 * * 7 -- 1 7 21 35 35 21 7 1 * * 8 -- 1 8 28 56 70 56 28 8 1 * * 9 -- 1 9 36 84 126 126 84 36 9 1 * * -------------------------------------------------------- * * Reference: "Exercices en Turbo Pascal By Claude Delannoy * * Eyrolles, 1997". * * * * C++ Release By J-P Moreau, Paris. * * (www.jpmoreau.fr) * ***********************************************************/ #include #define Nmax 15 //max. number of lines int t[Nmax]; //one line of triangle int nl; //desired number of lines int i,j; //current line/column void main() { // read number of lines & display caption printf("\n How many lines: "); scanf("%d", &nl); if (nl>Nmax) nl=Nmax; printf("\n\n"); printf(" p "); for (i=0; i0; j--) t[j] += t[j-1]; printf("%2d --", i); for (j=0; j<=i; j++) printf("%5d",t[j]); printf("\n"); } for (i=0; i<=nl; i++) printf("-----"); printf("\n"); } //end of file pastri.cpp