TRIANGULO DE PASCAL

yeo
28 de Mayo del 2005
necesito un programa en c++ que calcule e imprima el triangulo de pascal

Noel Solw
28 de Mayo del 2005
// program LR_19.cpp -pag 315
// 11/10/2003
// writen in Borlandc CPP - ver 3.1

#include <conio.h>
#include <iostream.h>
#include <iomanip.h>

#define MAX 12

int GetNum()
{
for(int x = 0;(x <= 0) || (x > MAX);)
{
cout << "type number of rows (from 1 to " << MAX << ") ---> ";
cin >> x;
}
cout << endl << endl;
return x;
} // GET NUM

void BuildMatrix(int a[MAX][MAX+1],int n)
{
int i,j;
for(i = 0;i < n;i++)
{
a[i][0] = 1;
for(j = 1; j < n+1;j++)
a[i][j] = 0;
}
for(i = 1;i < n;i++)
for(j = 1;j < i+1;j++)
a[i][j] = a[i-1][j-1] + a[i-1][j];
} // BUILD MATRIX

void Print(int a[MAX][MAX+1],int n)
{
int len = 34;
for(int i = 0;i < n;i++)
{
cout << setw(len) << " ";
len -= 3;
for(int j = 0;a[i][j];j++)
cout << setw(6) << a[i][j];
cout << endl;
}
cout << endl;
} // PRINT

void Process()
{
int n = GetNum();
int a[MAX][MAX+1];
BuildMatrix(a,n);
Print(a,n);
} // PROCESS

void main()
{
clrscr();
cout << "pascal triangle - formated output : n";
cout << "-----------------------------------------------------"
"-------------------------n";
Process();
cout << "-----------------------------------------------------"
"-------------------------n";
cout << "end of program - good bye ! ! !n";
getch();
} // MAIN