Q.no program to calculate the lcm of two number in c-programming.
In this program, we will calculate the lcm (least common multiple ) of two numbers by taking input form the user in c -programming.
The lcm of two integer a and b is the smallest positive integer that exactly divisible by both the number
(without any remainder),
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,l;
printf("enter the two numbers\n ");
scanf("%d %d",&a,&b);
for(l=a>b?a:b;l<=a*b;l++)
{
if(l%a==0&&l%b==0)
{
printf("the lcm of the two number is %d",l);
break;
}
}
getch();
}
output: enter the two numbers a=12 and b=16
the lcm of the two numbers is 48.
No comments:
Post a Comment