C program to find hcf (gcd) and lcm

1. Online Compilers - Compile & Run your C/C++ programs:

✅ Online Compilers

2. Ask your questions or clarify your/others doubts from,

✅ Online Discussion Forums by Fresh2Refresh.com





C program to find HCF (GCD) and LCM:

#include <stdio.h>

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

1. Online Compilers - Compile & Run your C/C++ programs:

✅ Online Compilers

2. Ask your questions or clarify your/others doubts from,

✅ Online Discussion Forums by Fresh2Refresh.com





Share this website !!!
Facebook Twitter Linkedin