-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPascalTriangle.cpp
More file actions
47 lines (37 loc) · 901 Bytes
/
PascalTriangle.cpp
File metadata and controls
47 lines (37 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
Pascal Triangle in C++:
C++ program to print Pascal triangle which you might have studied in Binomial
Theorem in Mathematics. Number of rows of Pascal triangle to print is entered by the user.
First four rows of Pascal triangle are shown below :-
1
1 1
1 2 1
1 3 3 1
*/
#include<iostream.h>
#include<conio.h>
long factorial(int);
main()
{
int i, n, c;
cout<<"Enter the number of rows you wish to see in pascal triangle\n";
cin>>n;
for ( i = 0 ; i < n ; i++ )
{
for ( c = 0 ; c <= ( n - i - 2 ) ; c++ )
cout<<" ";
for( c = 0 ; c <= i ; c++ )
cout<<" "<<factorial(i)/(factorial(c)*factorial(i-c));
cout<<endl;
}
getch();
return 0;
}
long factorial(int n)
{
int c;
long result = 1;
for( c = 1 ; c <= n ; c++ )
result = result*c;
return ( result );
}