Pages

Finding LCM and HCM of Two Number in C

In this example, we are going to find LCM and HCM of two integer.

Source Code:
#include <stdio.h>
#include <conio.h>

int main()
{
    int a, b, x, y, temp,hcm,lcm;
    printf("\tProgram to find LCM and HCM of Two Numbers");
    printf("\n------------------------------------------------------\n");

    printf("Enter Two Numbers : ");
    scanf("%d %d", &x, &y);
    a = x;
    b = y;
   //calculate hcm by interchanging position
    while(b != 0)
   {
       temp = b;
       b = a % temp;
       a = temp;
   }
   hcm = a;
   //calculate lcm
   lcm = (x*y)/hcm;
   //display hcm and lcm
   printf("HCM = %d, LCM = %d",hcm,lcm);
   getch();
   return 0;
}


Output:

@msucil

Phasellus facilisis convallis metus, ut imperdiet augue auctor nec. Duis at velit id augue lobortis porta. Sed varius, enim accumsan aliquam tincidunt, tortor urna vulputate quam, eget finibus urna est in augue.

No comments:

Post a Comment