import java.util.Scanner;
      public class Main 
      {
           public static void main(String[] args)
           {
                //initialize the variable
                int row,c=1,k,i,j;
                //take user input for number of row
                System.out.print("Enter the number of row ");
                Scanner sc = new Scanner(System.in);
                row = sc.nextInt();
                //declare outer loop for every new row.
                for(i=0;i<row;i++)
                {
                   //first inner loop for print space.
                   for(k=1;k<=row-i;k++)
                        System.out.print(" ");
                   //Second inner loop for print number in a row
                   for(j=0;j<=i;j++)
                   {
                       //if j or i is 0 so it will print 1
                       if (j==0||i==0)
                            c=1;
                       //we need to perform this calculation
                       else
                            c=c*(i-j+1)/j;
                       System.out.print(" "+c);
                   }
                   System.out.println();
                 }
            }
      }
      
      Java language logo

      Pascal triangle

      0

      0

      avatar
      drzyadav

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.