Example & Tutorial understanding programming in easy ways.

Write a program to find the LCM of the two number

LCM:
Stand for Lowest common multiple

Example-
LCM of 5 and 6 is 30
LCM of 4 and 6 is 12
LCM of 10 and 30 is 30


program-

#include< stdio.h>
int main() {
int i,n1,n2,max;
printf("Enter first number");
scanf("%d",&n1);
printf("Enter second number");
scanf("%d",&n2);
if(n1>n2)
max=n1;
else
max=n2;
for(i=max;i< =n1*n2;i++)
{
if(i%n1==0 && i%n2==0)
{
printf("LCM is %d",i);
break;
}
}
}


output-

Enter first number
5
Enter second number
15
LCM is 15

Enter first number
5
Enter second number
6
LCM is 30

-In this program, we take an input of two integer number and try to find there LCM.
-We run loop starting from largest number to multiply of both number.
-In between, if any value that is divisible by both, then it is considered as LCM of both number so we break the loop and display the LCM.




Read More →
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!