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; //asking user to enter two numbers and reading them 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
C PROGRAMMING TUTORIALS
- C Program to Add Spaces in a String
- C Program To Add Digits Of A Number
- C Program To Find Leap Year
- C Program To Append Data Into A File
- C Program to Accept Only Integer Values
- C Program To Arrange Numbers In Descending Order
- C Program to Add Days to Date
- C Program to Add Two Fractions
- C Program To Reverse A Number
- C Program to Find Maximum and Minimum Numbers
- C Program to Read a Text File
- C Program to Convert Decimal to Hexadecimal
- C Program to Convert Decimal to Binary
- C Program to Convert Celsius to Fahrenheit
- C Program To Find Absolute Value
- Ternary Operator Program in C
- C Program For Addition Table Using For Loop
- Denomination Program in C
- C Program to Print Multiplication Table
- C Program Array with Example