Skip to content

Commit

Permalink
day15 (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spreeha authored and MadhavBahl committed Jan 15, 2019
1 parent 1845d2d commit 995dc51
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
37 changes: 37 additions & 0 deletions day15/Java/PascalTriangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package recursion;

/**
* @date 09/01/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class PascalTriangle {
public static int pascal(int r,int c)
{
if(r==c || c==0)
return 1;
else
return pascal(r-1,c)+pascal(r-1,c-1);
}
public static void print(int n)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<=i;j++)
System.out.print(pascal(i,j)+" ");
System.out.println();
}
}
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
int n;
n=sc.nextInt();
print(n);
}
}
36 changes: 36 additions & 0 deletions day15/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,41 @@ def main():
print(f'Pascal triangle cannot have {num} rows')

main()
```

## Java Implementation

### [Solution](./Java/PascalTriangle.java)

```java
/**
* @date 09/01/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class PascalTriangle {
public static int pascal(int r,int c)
{
if(r==c || c==0)
return 1;
else
return pascal(r-1,c)+pascal(r-1,c-1);
}
public static void print(int n)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<=i;j++)
System.out.print(pascal(i,j)+" ");
System.out.println();
}
}
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
int n;
n=sc.nextInt();
print(n);
}
}
```

0 comments on commit 995dc51

Please sign in to comment.