Q:

C program to find HCF and LCM

0

C program to find HCF and LCM

C program to find HCF and LCM: The code below finds the highest common factor and the least common multiple of two integers. HCF is also known as the greatest common divisor (GCD) or the greatest common factor (GCF).

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include 
int main() {
  int a, b, x, y, t, gcd, lcm;

  printf("Enter two integers\n");
  scanf("%d%d", &x, &y);

  a = x;
  b = y;

  while (b != 0) {
    t = b;
    b = a % b;
    a = t;
  }

  gcd = a;
  lcm = (x*y)/gcd;

  printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
  printf("Least common multiple of %d and %d = %d\n", x, y, lcm);

  return 0;
}

output:

Enter two integers

2

3

Greatest common divisor of 2 and 3 = 1

Least common multiple of 2 and 3 = 6

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now