Discussion Forums

New User? Please read instructions!

C program to find HCF (GCD) and LCM  

  RSS

thiyagarajan.s
Active Member
Joined: 2 months  ago
Posts: 14
27/01/2017 10:03 am  

C program to find HCF (GCD) and LCM


ReplyQuote
prakash
Eminent Member
Joined: 2 months  ago
Posts: 20
16/02/2017 1:24 pm  

Hi,

C program to find HCF (GCD) and LCM is below.

 

#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


ReplyQuote
  
Working

Please Login or Register

Ask your questions or clarify your/others doubts from,

✅ Online Discussion Forums by Fresh2Refresh.com





Share this website !!!
Facebook Twitter Linkedin

Close
We Support JALLIKATTU !!!
We Support JALLIKATTU!
By Fresh2Refresh.com
Show Your Support as well. Thanks!