Friday, June 26, 2020

C Program to Find LCM of two Numbers

C Program to Find LCM of two Numbers

PROBLEM STATEMENT:

The LCM of two integers n1 and n2 is the smallest positive integer that is perfectly divisible by both n1 and n2 (without a remainder). For example, the LCM of 72 and 120 is 360.

PROGRAM:

#include <stdio.h>
int main() 
{
    int n1, n2, min;
    printf("Enter two positive integers: ");
    scanf("%d %d", &n1, &n2);
    if (n1 > n2)
    min= n1;
    else
    min= n2;
    while (1) 
    {
        if (min % n1 == 0 && min % n2 == 0)
        {
            printf("The LCM is %d",min);
            break;
        }
        ++min;
    }
    return 0;
}
OUTPUT:
Enter two positive integers: 72 120                                                                                   
The LCM is 360 



No comments:

Post a Comment