#include <iostream>
using namespace std;
class pasc
{
public:
int coef=1;
    void pasca(int rows)
    {
        system("cls");
        for (int i = 0; i < rows; i++)
        {
            for (int space = 1; space <= rows - i; space++)
            {
                cout << " ";
            }
            for (int j = 0; j <= i; j++)
            {
                if (i == 0 || j == 0)
                {
                    coef = 1;
                }
                else
                    coef = (coef * (i - j + 1)) / j;
                cout << coef << " ";
            }
            cout << endl;
        }
    }
};
int main()
{
    int rows;
    system("cls");
    cout << "enter no. of rows for pascal triangle pattern\n";
    cin >> rows;
    pasc a;
    a.pasca(rows);
    return 0;
}
 





No comments:
Post a Comment