import java.util.Scanner;
public class Main1
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
int n;
System.out.println("Enter the no of rows to print : ");
n=sc.nextInt();
int p[][];
p= new int[n][];
for(int i=0;i<n;i++)
p[i] = new int[i+1];
for(int i=0;i<n;i++)
{
p[i][0]=p[i][i]=1;
for(int j=1;j<i;j++)
{
p[i][j]= p[i-1][j-1]+ p[i-1][j];
}
}
System.out.println("\n\n");
for(int row[] : p)
{
for(int trm : row)
System.out.printf("%5d",trm);
System.out.println ();
}
}
}
public class Main1
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
int n;
System.out.println("Enter the no of rows to print : ");
n=sc.nextInt();
int p[][];
p= new int[n][];
for(int i=0;i<n;i++)
p[i] = new int[i+1];
for(int i=0;i<n;i++)
{
p[i][0]=p[i][i]=1;
for(int j=1;j<i;j++)
{
p[i][j]= p[i-1][j-1]+ p[i-1][j];
}
}
System.out.println("\n\n");
for(int row[] : p)
{
for(int trm : row)
System.out.printf("%5d",trm);
System.out.println ();
}
}
}
No comments:
Post a Comment