Thursday, April 2, 2020

c program to find lcm of two numbers using while loop

C program to find lcm of two numbers using while loop

  • The LCM of two numbers n1 and n2  is the smallest positive integer that is perfectly divisible by both n1 and n2. 
#include 
int main()
{
    int n1, n2, min; // integer variables
    printf("Enter two positive integers: "); // Entered user input
    scanf("%d %d", &n1, &n2);

    // maximum number between n1 and n2 is stored in min
    min = (n1 > n2) ? n1 : n2; 

    while (1) 
    {
        if (min % n1 == 0 && min % n2 == 0) 
   {
            printf("The LCM of %d and %d is %d.", n1, n2, min);
            break;
          }
        ++min;
    }
    return 0;
}
return 0;
}
Output

Enter tow positive integer  number = 72 120
The LCM of 72 and 120 is = 360 
Happy Coding
Location: Pakistan

0 comments:

Post a Comment

Recent Posts