Created
November 17, 2018 18:54
-
-
Save Abdulazizsayed/ebf009e7c1be8f79319a3d43e0dbcdf5 to your computer and use it in GitHub Desktop.
Pascal's triangle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
int Pascal_Tri(int row ,int col){ | |
if(row == 0 || col == 0){ | |
return 1; | |
} | |
else if(row == col){ | |
return 1; | |
} | |
return Pascal_Tri(row-1 ,col) + Pascal_Tri(row-1 ,col-1); | |
} | |
int main() | |
{ | |
int row ; | |
cout<<"Enter number of row : "; | |
cin>>row; | |
for(int i=0 ; i<row ; i++) | |
{ | |
for(int k= row - i - 1 ; k>0 ; k--) | |
{ | |
cout<<" "; | |
} | |
for(int j=0 ; j<= i ; j++) | |
{ | |
cout<<Pascal_Tri(i,j)<<" "; | |
} | |
cout<<endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment