Skip to content

Commit

Permalink
Pascal's_Triangle (jainaman224#738)
Browse files Browse the repository at this point in the history
* Pascal's_Triangle.c

* Pascal’s_Triangle.cpp
  • Loading branch information
somya-kapoor authored and ayushin78 committed Mar 24, 2019
1 parent d037738 commit 5e36fb3
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Pascal's_Triangle/Pascal's_Triangle.c
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
39 changes: 39 additions & 0 deletions Pascal’s_Triangle/Pascal’s_Triangle.cpp
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

0 comments on commit 5e36fb3

Please sign in to comment.