Skip to content

Commit

Permalink
Merge pull request tarunsinghofficial#386 from bhawanachaudhary/newuser
Browse files Browse the repository at this point in the history
Java Program for Pascal's Triangle added
  • Loading branch information
tarunsinghofficial committed Oct 19, 2020
2 parents 0400a56 + 9760c72 commit 02305a2
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Java_Programs_for_beginners/pascal_triangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
public class pascalstriangle{
static int factorial(int n)
{
int f;
for(f=1;n>1;n--)
{
f *=n;
}
return f;
}
static int ncr(int n, int r)
{
return factorial(n)/factorial(n-r)*factorial(r);
}
public static void main(String[]args)
{
System.out.println();
int n,i,j;
n=5;
for(i=0;i<=n;i++)
{
for(j=0;j<=n-i;j++)
{
System.out.print(" ");
}
for(j=0;j<=i;j++)
{
System.out.print(" "+ncr(i,j));
}
System.out.println();
}
}
}

0 comments on commit 02305a2

Please sign in to comment.