Solved programming problem

How to find LCM of two Number in C

Source code

#include<stdio.h>

int main()

{

    int n,m,i,temp;

    printf("Please Enter 1st  Number: ");

    scanf("%d",&n);

    printf("Please Enter 2nd  Number: ");

    scanf("%d",&m);

    ///finding the biggest number

    if(n>=m)

    {

        temp=n;

    }

    else

    {

      temp=m;

    }

    ///Finding the LCM

    while(1)

    {

        if(temp%n==0 && temp%m==0)

        {

          printf("
The LCM of %d and %d is: %d
",n,m,temp);

          break;

        }

        temp++;

    }

    return 0;

}

Output

Please Enter 1st  Number:10

Please Enter 2nd  Number:15

The LCM of 10 and 15 is:30

Join the discussion

Add your comment