-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1845d2d
commit 995dc51
Showing
2 changed files
with
73 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 @@ | ||
/* | ||
* 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); | ||
} | ||
} |
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