 # C Program To Find LCM GCD Of Two Numbers

C Program To Find LCM GCD Of Two Numbers. If you are looking for C program to calculate LCM and GCD of two numbers, here in this tutorial we will help you to learn how to write a program to find LCM in C language.

## C Program to Find LCM and GCD

Learn how to write a C program to find LCM. Writing C Program to finding GCD of a number can be done using various techniques but here in this program, we show how to write a C program to find LCM GCD of two numbers in a proper way.

### C Program to Find LCM and GCD of Two Numbers Source Code

```/* C program to find the LCM and GCD of two numbers - LcmGcd.C */

#include <stdio.h>

void main()
{
//variable declaration
int num1, num2, gcd, lcm, remainder, numerator, denominator;

printf("Enter two numbers\n");
scanf("%d %d", &num1, &num2);

//checking for bigger number
if (num1 > num2)
{
numerator = num1;
denominator = num2;
}
else
{
numerator = num2;
denominator = num1;
}

//calculating remainder
remainder = numerator % denominator;

//logic to find gcd and lcm of two numbers
while (remainder != 0)
{
numerator = denominator;
denominator = remainder;
remainder = numerator % denominator;
}

//finding lcm and gcd of two numbers
gcd = denominator;
lcm = num1 * num2 / gcd;

//printing lcm and gcd of two numbers
printf("GCD of %d and %d = %d\n", num1, num2, gcd);
printf("LCM of %d and %d = %d\n", num1, num2, lcm);
}```

### C Program to Find LCM and GCD of Two Numbers Output

Enter two numbers

65

30

GCD of 65 and 30 = 5

LCM of 65 and 30 = 390