pascal triangle in c 2b 2b

Solutions on MaxInterview for pascal triangle in c 2b 2b by the best coders in the world

showing results for - "pascal triangle in c 2b 2b"
Capucine
02 Oct 2017
1#include <iostream>
2using namespace std;
3
4int main()
5{
6    int rows, coef = 1;
7
8    cout << "Enter number of rows: ";
9    cin >> rows;
10
11    for(int i = 0; i < rows; i++)
12    {
13        for(int space = 1; space <= rows-i; space++)
14            cout <<"  ";
15
16        for(int j = 0; j <= i; j++)
17        {
18            if (j == 0 || i == 0)
19                coef = 1;
20            else
21                coef = coef*(i-j+1)/j;
22
23            cout << coef << "   ";
24        }
25        cout << endl;
26    }
27
28    return 0;
29}