Write a C program for LCM of Two Numbers

 TASK-

Write a C program for LCM of Two Numbers.

LCM: Least common multiple , its a number which is closer to certain with having quality of being least common multiple for certain numbers.


E.g LCM of 2 and 6 is 6, The common multiple of 2,6 also include 12 but least one is 6.

CODE:

#include<stdio.h>
int main()
{
int i,l,f,x,y;
//Taking two number e.g 2,6

    printf("Enter two numbers: ");
printf("\n1- ");
scanf("%d",&x);
printf("\n2- ");
scanf("%d",&y);
f=x*y; //Greatest possible number
if (x<y)
i=x;
else
i=y;
for (i;i<=f;i++)
{
if (i%x==0&&i%y==0)
{
l=i;
break;
}
}
printf("Lcm of %d and %d is %d",x,y,l);
getchar();
return 0;
}

EXPECTED OUTPUT:




NEED WORK PRODUCE WORK

My name is Abdul Rehman I am from Pakistan. I am doing BS in Computer and information sciences. Currently, I am creating these blogs to help students of computer sciences all over the world..

Post a Comment (0)
Previous Post Next Post