C program to find LCM of the given 3 numbers

In this program we will use for loop to find lcm of the given 3 numbers. So code for the program is given below.

Code for C program to find LCM of the given 3 numbers

#include<stdio.h>
#include<conio.h>
int main()
{
int i, n1, n2,n3,l1,l2,l3,lcm,gcd;
scanf("%d %d %d",&n1,&n2,&n3);
for(i=1;i<=n1&&i<=n2&&i<=n3;i++)
{
if(n1%i==0 && n2%i==0 &&n3%i==0)
{
gcd=i;
}
}
l1=n1/gcd;
l2=n2/gcd;
l3=n3/gcd;
lcm=l1*l2*l3*gcd;
printf("%d",lcm);
return 0;
 }

Output

Enter any three positive integers 2 4 6
LCM of two integers is 12

Read: C program to check the given number is Adam’s number


If You Like This Page Then Make Sure To Follow Us on Facebook, G News and Subscribe Our YouTube Channel. We will provide you updates daily.
Shares
facebook sharing button Share
twitter sharing button Tweet
whatsapp sharing button Share
telegram sharing button Share
pinterest sharing button Pin

Leave a Comment