LCM is least common factor.

For example, L C M of 16 and 20 will be 2 x 2 x 2 x 2 x 5 = 80.

GCD is greatest common divisor   of two or more integers, which are not all zero, is the largest positive integer that divides each of the integers.
For examplethe G.C.D of 8 and 12 is 4.

Source Code:

  1. # include <stdio.h>
  2. int main()
  3. {
  4. int lcm,hcf,m,n,m1,n1;
  5. printf("Give the value= ");
  6. scanf ("%d %d",&m,&n);
  7. m1=m;
  8. n1=n;
  9. while(m1!=n1)
  10. {
  11. if(m1>n1)
  12. m1=m1-n1;
  13. else
  14. n1=n1-m1;
  15. }
  16. hcf=m1;
  17. lcm=(m*n)/hcf;
  18. printf("HCF=%d\t LCM=%d",hcf,lcm);
  19. return 0;
  20. }

Output:

      1.   Give the value=5 15
            HCF=5 LCM=15

      2.  Give the value=15 50
           HCF=5 LCM=150

0 comments:

Post a Comment