Page 567 - ComputerScience_Class_11
P. 567

7               int i,f=1;

                   8               for(i=1;i<=n;i++)
                   9               {

                   10                  f=f*i;
                   11              }
                   12              return f;

                   13          }
                   14          public static void main(String args[])
                   15          {

                   16              Scanner sc= new Scanner(System.in);
                   17              int n , i, j;
                   18              pascals pas = new pascals();

                   19                System.out.print("Enter the number of lines in the pascals triangle : ");
                   20              n=sc.nextInt();
                   21              for (i = 0; i < n; i++)

                   22              {
                   23                  for (j = 0; j < n - i; j++)
                   24                  {

                   25                      System.out.print(" ");  // for giving space
                   26                  }
                   27                  for (j = 0; j <= i; j++)

                   28                  {
                   29                       System.out.print(" "+ pas.findfactorial(i)/ (pas.findfactorial(i
                                              - j)* pas.findfactorial(j))); // For printing
                   30                  }

                   31                  System.out.println();
                   32              }
                   33          } }

                 The output of the preceding program is as follows:

                       BlueJ: Terminal Window - Java
                   Options

                  Enter the number of lines in the pascals triangle : 6
                          1
                         1 1
                        1 2 1
                       1 3 3 1
                      1 4 6 4 1
                     1 5 10 10 5 1





                                                                                                Internal Assessment  565
   562   563   564   565   566   567   568   569   570   571   572