Skip to content

Instantly share code, notes, and snippets.

@Abdulazizsayed
Created November 17, 2018 18:54
Show Gist options
  • Save Abdulazizsayed/ebf009e7c1be8f79319a3d43e0dbcdf5 to your computer and use it in GitHub Desktop.
Save Abdulazizsayed/ebf009e7c1be8f79319a3d43e0dbcdf5 to your computer and use it in GitHub Desktop.
Pascal's triangle
#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