write a program to generate pascals triangle ...15 rows
Answers
Answer:
Pascal’s Triangle
Pascal’s triangle is a triangular array of the binomial coefficients. Write a function that takes an integer value n as input and prints first n lines of the Pascal’s triangle. Following are the first 6 rows of Pascal’s Triangle.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
Number of entries in every line is equal to line number. For example, the first line has “1”, the second line has “1 1”, the third line has “1 2 1”,.. and so on. Every entry in a line is value of a Binomial Coefficient. The value of ith entry in line number line is C(line, i). The value can be calculated using following formula
Answer:
/***********************************
* Pascal's triangle *
***********************************/
/**
* Pascal's pattern is generated from the top of the pyramid i.e. first row.
* Triangle is a perfectly symmetrical mirror image having a line down through the middle innermost digits.
* Code created by Mahnaz Hazra
**/
import java.util.*;
public class Main //Or Public class PascalTriangle
{
public static void main(String[] args)
{
Scanner Scn = new Scanner(System.in);
int mn = Scn.nextInt() + 1;
if(mn > 15)
{
System.out.println("Note : The neatnest of the format fails after 15.");
}
System.out.println(); //Print a new line
for(int n = 0; n < mn; n++)
{
System.out.format("%n");
for(int i = mn-n; i > 0; i--)
{
System.out.format("%3s", "");
}
System.out.format("1");
int t = 1;
for(int i = 1;i <= n; i++)
{
t = (t * (n +1 - i) ) /i;
System.out.format(" %5d", t);
}
}
}
}
Please mark me as brainliest.........