forked from jainaman224/Algo_Ds_Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Pascal's_Triangle.c * Pascal’s_Triangle.cpp
- Loading branch information
1 parent
d037738
commit 5e36fb3
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <stdio.h> | ||
|
||
int factorial(int num) | ||
{ | ||
int fact; | ||
for(fact = 1; num > 1; num--) | ||
fact *= num; | ||
return fact; | ||
} | ||
|
||
int main() | ||
{ | ||
int num, i, j; | ||
printf("Enter the numbers of rows "); | ||
scanf("%d",&num); | ||
|
||
for(i = 0; i < num; i++) | ||
{ | ||
for(j = 0; j < num-i; j++) | ||
printf(" "); | ||
|
||
for(j = 0; j <= i; j++) | ||
printf(" %3d",factorial(i)/(factorial(j)*factorial(i-j)) ); | ||
|
||
printf("\n"); | ||
} | ||
return 0; | ||
} | ||
|
||
//INPUT:Enter the numbers of rows 6 | ||
//OUTPUT: | ||
// 1 | ||
// 1 1 | ||
// 1 2 1 | ||
// 1 3 3 1 | ||
// 1 4 6 4 1 | ||
// 1 5 10 10 5 1 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <stdio.h> | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int factorial(int num) | ||
{ | ||
int fact; | ||
for(fact = 1; num > 1; num--) | ||
fact *= num; | ||
return fact; | ||
} | ||
|
||
int main() | ||
{ | ||
int num, i, j; | ||
cout<<"Enter the numbers of rows "; | ||
cin>>num; | ||
|
||
for(i = 0; i < num; i++) | ||
{ | ||
for(j = 0; j < num-i; j++) | ||
cout<<" "; | ||
|
||
for(j = 0; j <= i; j++) | ||
cout<<" "<<factorial(i)/(factorial(j)*factorial(i-j))<<" "; | ||
|
||
cout<<"\n"; | ||
} | ||
return 0; | ||
} | ||
|
||
//INPUT:Enter the numbers of rows 6 | ||
//OUTPUT: | ||
// 1 | ||
// 1 1 | ||
// 1 2 1 | ||
// 1 3 3 1 | ||
// 1 4 6 4 1 | ||
// 1 5 10 10 5 1 |