-
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.
- Loading branch information
1 parent
115e44a
commit a1f3aee
Showing
1 changed file
with
56 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,56 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class PascalTriangle { | ||
|
||
public static int fact(int n) | ||
{ | ||
if(n==0) | ||
{ | ||
return 1; | ||
} | ||
else | ||
{ | ||
int a = n*fact(n-1); | ||
return a; | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
int n = scanner.nextInt(); | ||
for(int i =0; i<n; i++) | ||
{ | ||
int space= n-i-1; | ||
while(space>0) | ||
{ | ||
System.out.print(" "); | ||
space--; | ||
} | ||
|
||
int num= 2*i+1; | ||
int index=1; | ||
|
||
for(int j= num; j>0; j--) | ||
{ | ||
if(j==1 || j==num) | ||
{ | ||
System.out.print(1); | ||
} | ||
else if(j%2==0) | ||
{ | ||
System.out.print(" "); | ||
} | ||
else | ||
{ | ||
int a = fact(i)/ (fact(i-index) *fact(index++)); | ||
System.out.print(a); | ||
} | ||
} | ||
|
||
System.out.println(""); | ||
} | ||
|
||
} | ||
} |