Answer: Find GCD by Euclid's method, then \( \text{LCM} = \frac{a \times b}{\text{GCD}} \).
Logic (12, 18): 18 % 12 = 6, 12 % 6 = 0, so GCD = 6 and LCM = 12 × 18 / 6 = 36.
Program:
#include <stdio.h>
int main()
{
int a, b, x, y, r, gcd, lcm;
printf("Enter two positive integers: ");
scanf("%d %d", &a, &b);
/* GCD by Euclid's method */
x = a;
y = b;
while (y != 0)
{
r = x % y;
x = y;
y = r;
}
gcd = x;
lcm = (a / gcd) * b; /* same as a*b/gcd, avoids overflow */
printf("GCD = %d\n", gcd);
printf("LCM of %d and %d = %d\n", a, b, lcm);
return 0;
}Sample output (actual run):
Enter two positive integers: 12 18
GCD = 6
LCM of 12 and 18 = 36