Code Box
---------------------------------------
/*Program to find L.C.M. of any two numbers */
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int num1,num2,a,b,count,lcm,i;
lcm=1;
printf("\n----------------- L.C.M. Calculator ---------------");
printf("\nEnter first number:");
scanf("%d",&a);
printf("\nEnter second number:");
scanf("%d",&b);
num1=a;
num2=b;
//prime factors are 2,3,5,7
printf("L.C.M. Factors :");
for(i=7;i>=2;)
{
count=0;
if(num1%i==0)
{
num1=num1/i;
count=1;
}
if(num2%i==0)
{
num2=num2/i;
count=1;
}
if(count==0)
{
i--;
}
else
{
printf("%d",i);
lcm=lcm*i;
}
}
//in case of prime number
printf(" %d %d ",num1,num2);
lcm=lcm*num1*num2;
printf("\nL.C.M. of %d & %d is : %d",a,b,lcm);
printf("\n\n-------------------------------------------");
getch();
}
No comments:
Post a Comment