C Program To Write A Program To Find The LCM(Lowest Common Multiple)c program for lcm. LCM stands for least common multiple. LCM of two or more numbers is the least number that is exactly divisible by each one of the given numbers. You can also refer for c porgram for hcf or gcd. Here is an example for how we can find lcm of two number, for c program for lcm : lcm of 8 and 16 is 32.
ALGORITHM:-
step 1 : Start
step 2 : Enter Any number to calculate LCM
step 3 : Calculate the Lowest Common Factor
step 4 : Stop the Execution
PROGRAM CODE:-
#include<stdio.h>
#include<conio.h>
int lcm(int , int);
int main()
{
int x,y,l;
printf("Enter any number two number to calculate the lcm \n");
scanf("%d%d",&x,&y);
l=lcm(x,y);
printf("\nlcm of %d & %d is %d ",x,y,l);
getch();
}
int lcm(int a, int b)
{
int p;
for(int i=1;i<=a;i++)
{
for(int j=1;j<=b;j++)
{
if(b*i==a*j)
{
p=b*i;
i=i+a;
}
}
}
return p;
}
OUTPUT:-
Enter Any number two number to calculate the LCM:
24
16
LCM of 24 and 16 is: 48
C Program To Calculate the LCM of any two number How to Calculate Lowest commond factor using c LCM Calculation using c
ConversionConversion EmoticonEmoticon