Thursday, May 30, 2019

find the LCM and HCF of two numbers in c

/*************************************************
    Write a Program to find the LCM and HCF of two numbers

 date:30/-05-2019
 created by:ANIL DURGAM

*****************************************************/

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x,y,a,b;
     printf("Enter two numbers");
     scanf("%d %d",&x,&y);
      a=x;
      b=y;
      while(a!=b)
        {
            if(a<b)
                a=a+x;
            else
                b=b+y;
        }
        printf("LCM of %d and %d is %d\n",x,y,a);
         a=x; b=y;
         while(a!=b)
            {
                if(a>b)
                    a=a-b;
                else
                    b=b-a;
                }
                printf("HCF of %d and %d is. %d\n", x, y, a) ;

    return 0;
}

No comments:

Post a Comment

python class topic video