Page 226 - CA_Blue( J )_Class9
P. 226

11                  System.out.print(", "+ c);
                    12                  a=b;

                    13                  b=c;
                    14              }

                    15          }
                    16      }

                  You will get the following output:



















                                  Write a program to input two numbers and print the Greatest Common Divisor (GCD) and
                    Program 16
                                  Lowest Common Multiples (LCM) of them.
                     1      import java.util.*;

                     2      class prog_gcd_lcm
                     3      {

                     4          public static void main ()
                     5          {

                     6              Scanner sc = new Scanner (System.in);
                     7              int s=0 , a, b, g,l;

                     8              System.out.println("Enter two numbers: ");
                     9              a=sc.nextInt ();
                    10              b=sc.nextInt ();

                    11              if(a<b)

                    12                  g = a;
                    13              else
                    14                  g = b;

                    15              while (g>=1)
                    16              {

                    17                  if(a%g==0 && b%g==0)
                    18                      { break;}



                   224    Touchpad Computer Applications-IX
   221   222   223   224   225   226   227   228   229   230   231