Welcome

Hi! This blog is for beginners of c++ and java .You can check and pick codes for your programming assignments. This will also help you to understand the concepts of these programming languages. Its all about programming.

A Pascal triangle of any Size

Tuesday, June 7, 2011

#include <iostream.h>
#include <math.h>

void constructPascal(int numRows);

int main(void)
{
  int numRows;

  cout <<"Enter the number of rows of the Pascal Triangle: ";
  cin >> numRows;
  constructPascal(numRows);

return 0;
}


void constructPascal(int numRows)
{
   int n,k;
   int simple[23][23] = {1};
   
    for(n=1; n<=(numRows-1); n++)
    {
         for(k=1; k<=(numRows-1); k++)
         {
             simple[n][k]=simple[n-1][k-1]+simple[n-1][k];
             cout << "\t"<<simple[n][k];
         }
    cout <<"\n";
    }
}