C program to find LCM of two numbers - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Friday, January 3, 2020

C program to find LCM of two numbers - My CS Tutorial

C program to find LCM ( LEAST COMMON MULTIPLE ) of two numbers.

In this tutorial we will learn how to write a c program that find the LCM of two numbers.LCM (Least Common Multiple) of two numbers is the smallest number which can be divided by both numbers.

Example :-  LCM of 15 and 25 is 75 and LCM of 11 and 5 is 55.



C program code


#include<stdio.h>
#include<conio.h>
void main()
{
int n1,n2,i,gcd,lcm;
clrscr();
printf("\n ENTER THE VALUE OF N1(FIRST NUMBER):\n ");
scanf("%d",&n1);
printf("\n ENTER THE VALUE OF N2(SECOND NUMBER):\n ");
scanf("%d",&n2);
for(i=1;i<=n1&&i<=n2;i++)
{
if(n1%i==0&&n2%i==0)
gcd=i;
}
lcm=(n1*n2)/gcd;
printf("\n THE LCM IS:\n %d",lcm);
getch();
}


OUTPUT:





In this output we will see, this program find the LCM of two numbers.
In the first we will enter two numbers and stored in variables n1 and n2.
The LCM stored in lcm variable.


Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com

Created by-- HARSH CHAUHAN

No comments:

Post a Comment