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}
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}
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}