C++ Programming Code Examples C++ > Pyramid Patterns Code Examples C++ Programming Code to Print Pascal Triangle C++ Programming Code to Print Pascal Triangle To print pascal triangle in C++ programming, you have to ask to the user to enter the number of line (upto which he/she want to print pascal triangle). So to print pascal triangle, you have to use three for loops as shown here in the following program. Following C++ program ask to the user to enter number of line or row upto which the Pascal triangle will be printed to print the Pascal triangle and display it on the screen: /* C++ Program - Print Pascal Triangle */ #include<iostream.h> #include<conio.h> long fact(int); void main() { clrscr(); int j, n, c; cout<<"Upto how many line (Enter number of rows) : "; cin>>n; for(j=0; j<n; j++) { for(c=0; c<=(n-j-2); c++) { cout<<" "; } for(c=0; c<=j; c++) { cout<<fact(j)/(fact(c)*fact(j-c)); } cout<<"\n"; } getch(); } long fact(int n) { int c; long res=1; for(c=1; c<=n; c++) { res = res*c; } return (res); }