Q-6. C programming GCD , LCM

0
//c programming GCD, LCM



  1. #include<stdio.h>
  2. int main ( )
  3. {
  4.     int num1,num2,n1,n2,rem,gcd,lcm;

  5.     printf ("Enter 2 number :");
  6.     scanf ( "%d %d",&num1,&num2);

  7.     n1=num1;
  8.     n2=num2;
  9.     while (n2!=0)
  10.     {
  11.         rem = n1%n2;
  12.         n1  = n2;
  13.         n2  = rem;
  14.     }
  15.     gcd=n1;
  16.     lcm=( num1*num2)/gcd;

  17.     printf ( "GCD=%d\n",gcd);
  18.     printf ("LCM=%d\n",lcm);
  19.     return 0;
  20. }

Post a Comment

0Comments
Post a Comment (0)