C Program for LCM Of Two Numbers
LCM of two numbers
Here, in this page we will dicuss the LCM of two numbers in C . 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.
- Take two integers value from the user and store them in variable say n1 and n2.
- Create a function say lcm_two_no() that takes two integers value as parameters.
- Now, in the function lcm_two_no(), Declare two variables say check1 and check2.
- Copy the value of n1 and n2 of variable to check1 and check2 variables respectively.
- Initialize the while loop where condition is while(check1!=check2).
- In while loop there are two condition If check1<check2
- If condition is true then increment the check1 variable by n1 value, i.e, check1=check1+n1; .
- Otherwise increment the check2 variable by n2 i.e,
- 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.