C Program for LCM Of Two Numbers
Write a C program to find the LCM of two number.
The Least Common Multiple (LCM) is also referred to as the Lowest Common Multiple (LCM) and Least Common Denominator (LCD). The least common multiple, or LCM, is another number that’s useful in solving many math problems. Let’s find the LCM of 12 and 44. One way to find the least common multiple of two numbers is to first list the prime factors of each number.
12 = 2 × 2 × 3
44 = 2 × 2 × 11
A C program can calculate the Lowest Common Multiple (LCM) of two numbers. The method includes finding out the maximum values among two numbers, which are common in both the numbers. The algorithm below will help to calculate the LCM of two numbers.
- Initialize variable check1 and check2.
- Copy the value of n1 and n2 of variable .
- Initialize the while loop where condition is while(check1!=check2).
- In while loop there are two condition If check1<check2
- it is true use this condition check1=check1+n1; .
- Print the value of check1 or check2.
C Program to calculate LCM of two numbers.
/** C program to calculate the LCM of two numbers */
//to take user input n1,n2
printf("Enter two numbers: ");
//call of user define function
//function to calculate l.c.m
void lcm_two_no(int n1,int n2)
//to use of duplicity value
//to find lcm of number
//for condition true
//for condition false
printf("\nL.C.M of %d and %d is: %d",n1,n2,check1);
Enter any two numbers: 12 30 LCM of 12 and 30 is 60.