C Program to find LCM using while Loop and if Statement




c programming
c programming
/**********************************************************************
LCM using while Loop and if Statement using C Program
 **********************************************************************/
#include <stdio.h>
int main()
{
  int number_1, number_2, minMultiple;
  printf("Enter two positive integers: ");
  scanf("%d %d", &number_1, &number_2);

  // maximum number between number_1 and number_2 is stored in minMultiple
  minMultiple = (number_1 > number_2) ? number_1 : number_2;

  // Always true
  while(1)
    {
      if( minMultiple%number_1==0 && minMultiple % number_2==0 )
        {
          printf("The LCM of %d and %d is %d.", number_1, number_2,minMultiple);
          break;
        }
      ++minMultiple;
    }
  return 0;
}



/*

OUTPUT:

Enter two positive integers: 11
12
The LCM of 11 and 12 is 132


*/

 


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*