pascal triangle using c 2b 2b

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

showing results for - "pascal triangle using c 2b 2b"
Alexander
21 Apr 2016
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}
Roberto
15 May 2018
1#include <iostream>
2using namespace std;
3
4
5int fact(int num){
6    int factorial = 1;
7    for (int i = 2; i <= num; i++)
8    {
9        factorial = factorial * i;
10    }
11    return factorial;
12}
13
14int main(){
15    int n;
16    cout << "Enter number of rows: ";
17    cin >> n;
18
19    for (int i = 0; i < n; i++)
20    {
21        for (int j = 0; j <=i; j++)
22        {
23            cout << fact(i) / (fact(j) * fact(i - j)) << " ";
24        }
25        cout << endl;
26    }
27    
28}
Monica
18 Jun 2016
1int pascal(int row, int col) {
2  if (col == 0 || col == row) return 1;
3  else if(col == 1 || (col + 1) == row) return row;
4  else return pascal(row - 1, col - 1) + pascal(row - 1, col);
5}
queries leading to this page
c 2b 2b pascal triangleprogram to print pascal triangle in cppefficient c 2b 2b to displaye pascal 27s trianglepascal triangle using c 2b 2bfastest pascal triangle in c 2b 2bpascal triangle c 2b 2b vectorpascal triangle c 2b 2b 5cpascal triangle with piramid pattern outputc 2b 2b program for pascal trainglepascal triangle program in cpppascal 27s triangle cppc 2b 2b pascal 27s triangle c 2b 2bpascal trinagle in c 2b 2bprint pascal triangle in cpppascal triangle algorithm c 2b 2bc 2b 2b function display pascal trianglepascal 27s trianglepascal triangle c 2b 2bpascals triangle in cpppascal triangle printer c 2b 2bpascals triange code in cpphow to program pascal triangle in c 2b 2bc 2b 2b program to print pascal 27s triangle pascal 27s triangle c 2b 2bpascal triangle in c 2b 2bhow to make pascal triangle in c 2b 2bpascals triangle in c 2b 2bc 2b 2b print pascal trianglec 2b 2b pascal 27s trianglepascal triangle program in c 2b 2brow of pascal 27s triangle c 2b 2bpascal 27s triangle in c 2b 2b through pointerprint pascals triange code in cpppascal 27s triangle in cpppascals triangle using c 2b 2bpascal triangle numbers c 2b 2bprint the pattern of pascal 27s triangle in c 2b 2btriangle of pascal in c 2b 2bprogram to print the pascal triangle in cpppascal 27s triangle c 2b 2b programlogic of pascal triangle c 2b 2bpascal 27s triangle c 2b 2bpascal 27s triangle in c 2b 2bc 2b 2b program to form pascal 27s trianglepascals triangle c 2b 2bpascal triangle cpphow to print pascal triangle in c 2b 2bpascal triangle formula c 2b 2bpascal trangle c 2b 2bprint pascal triangle in c 2b 2bpascal triangle code c 2b 2bpascal triangle code in c 2b 2bpascal 27s triangle program in c 2b 2bpascal triangle using c 2b 2b