Skip to main content

Program to calculate HCF & LCM.

 Program to calculate HCF & LCM.


  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5.     int a, b, x, y, t, hcf, lcm;
  6.     printf("Enter two numbers : ");
  7.     scanf("%d%d", &x, &y);

  8.     a = x;
  9.     b = y;

  10.     while (b != 0)
  11.     {
  12.         t = b;
  13.         b = a % b;
  14.         a = t;
  15.     }

  16.     hcf = a;
  17.     lcm = (x * y) / hcf;

  18.     printf("\nHighest Common Factor of %d and %d : %d", x, y, hcf);
  19.     printf("\nLeast Common Multiple of %d and %d : %d", x, y, lcm);
  20. }

👉Execute👈


//OUTPUT
/*

*/