Friday 17 February 2017

Least Common Multiple

Q : Write a program to input two numbers and find out Least Common Multiple?

The smallest positive number that is a multiple of two or more numbers.

Solution : 

/*   ################################
     Girfa Student Help
     LCM
     for more visit : http://girfahelp.blogspot.in/p/c-language.html
     ################################

*/
#include<stdio.h>
void main()
{
    int min,max,lcm,i,x;
    printf("Enter first Number>> ");
    scanf("%d",&min);
    printf("Enter Second Number >> ");
    scanf("%d",&max);
    for(i=1;i<max;i++)
    {
           x=max*i;
           if(x%min==0)
           {
                lcm=x;
                break;
           }
    }
    printf("\n\tL.C.M is %d",lcm);
    getch();
}

No comments:

Post a Comment