Exforsys
+ Reply to Thread
Results 1 to 2 of 2

Generate Pascal's triangle

This is a discussion on Generate Pascal's triangle within the C and C++ forums, part of the Programming Talk category; I need to write a C++ program to generate pascal's triangle. Please help me.......

  1. #1
    Manyamanas is offline Member Array
    Join Date
    Dec 2010
    Answers
    32

    Generate Pascal's triangle

    I need to write a C++ program to generate pascal's triangle.

    Please help me....


  2. #2
    swapwarick's Avatar
    swapwarick is offline Member Array
    Join Date
    Mar 2011
    Location
    Pune,India
    Answers
    37
    #include <iostream>
    using namespace std;

    void printrow(int r, int q[][13]) {
    int e;
    for (e=0; e<13; e++) {
    cout << q[r][e] << " ";
    }
    cout << endl;
    return;
    }

    int main()
    {
    int n, p[13][13];
    int count = 0;
    cout << "Enter a row number."<< endl;
    cin >> n;
    while (n >= 0) {
    int count = 0;
    cout << "Enter a row number."<< endl;
    cin >> n;
    int x, y;
    for (x=0; x<=n; x++) {
    count++;
    for(y=0; y<=(count-1); y++) {
    if (x>n || y>x)
    {
    p[x][y] = 0;
    cout<<p[x][y];
    }
    else if (y==0 || y==x)
    {
    p[x][y] = 1;
    cout<<p[x][y];
    }
    else
    {
    p[x][y] = p[x-1][y-1] + p[x-1][y];
    cout<<p[x][y];
    }
    for (x=0;x<=n;x++ )
    {
    count++;
    for (y=0;y<=n;y++)
    {
    cout << p[n][y] <<" ";
    }
    }
    }
    return 0;
    }
    This code generates pascal triangle!!
    it was written by my brother...

    hope it will help u

    Swapwarick


Latest Article

Network Security Risk Assessment and Measurement

Read More...