Share your repls and programming experiences

← Back to all posts
22 Aug 19
jagdishhatwar (1)

#include<stdio.h>
int gcd(int x, int y);
int gcd(int x, int y) {
if (x == 0) {
return y;
}

while (y != 0) {
if (x > y) {
x = x - y;
}
else {
y = y - x;
}
}

return x;
}

int main() {
int x, y, hcf, lcm;

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

hcf = gcd(x, y);
lcm = (x*y)/hcf;

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

}