Page 211 - CA_Blue( J )_Class10
P. 211

2  {
                   3      public static void main()

                   4      {
                   5          int i,j;

                   6          for(i=1;i<=5;i++) {

                   7          for(j=1;j<=i;j++) {
                   8              System.out.print("1"+" "); }
                   9              for(j=i;j<=5;j++) {

                  10              System.out.print(j+" "); }
                  11              System.out.println();

                  12          }
                  13      }

                  14  }

                                To input number of lines and print the pascals triangle
                   Program 13   Say, n = 5

                                1
                                1 1
                                1 2 1
                                1 3 3 1
                                1 4 6 4 1


                    1 import java.util.*;
                    2 class pascal_triangle

                    3 {
                    4     public static void main()

                    5     {
                    6         Scanner sc = new Scanner(System.in);

                    7         int n,sp,i,j,v=1;

                    8         System.out.print("Input number of rows: ");

                    9         n = sc.nextInt();
                   10         for(i=0;i<n;i++)

                   11         {

                   12             for(j=0;j<=i;j++)

                   13             {    if (j==0||i==0)
                   14                     v=1;

                    15                 else


                                                                                                                       209
                                                                                                         Nested Loop   209
   206   207   208   209   210   211   212   213   214   215   216