Computer Science, asked by Nik7117, 1 year ago

Write a program in Java to print Pascal's triangle

Answers

Answered by vaishu00
3
/* Java Program Example - Print Pascal Triangle */

import java.util.Scanner;

public class JavaPascalTriangle
{
public static void main(String args[])
{
int r, i, k, number=1, j;
Scanner scan = new Scanner(System.in);

System.out.print("Enter Number of Rows : ");
r = scan.nextInt();

for(i=0;i<r;i++)
{
for(k=r; k>i; k--)
{
System.out.print(" ");
}
number = 1;
for(j=0;j<=i;j++)
{
System.out.print(number+ " ");
number = number * (i - j) / (j + 1);
}
System.out.println();
}
}
}




I hope this answer help to you

Nik7117: thanks didi
Similar questions