Q:

C PROGRAM TO FIND HCF (GCD) AND LCM:

0

C PROGRAM TO FIND HCF (GCD) AND LCM:

All Answers

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

int main()

{

int a, b, x, y, temp, gcd, lcm;

printf(“Please enter two numbers one by one\n”);

scanf(“%d”, &x);

scanf(“%d”, &y);

 

a = x;

b = y;

 

while (b != 0)

{

temp = b;

b = a % b;

a = temp;

}

 

gcd = a;

lcm = (x*y)/gcd;

printf(“GCD:\nGreatest common divisor of the numbers %d and %d = %d\n”, x, y, gcd);

printf(“LCM:\nLeast common multiple of the numbers %d and %d = %d\n”, x, y, lcm);

 

return 0;

}

 

Output:

Please enter two numbers one by one

8

6

GCD:

Greatest common divisor of the numbers 8 and 6 = 2

LCM:

Least common multiple of the numbers 8 and 6 = 24

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