C Program

Object:-Write a Program to find LCM and HCF of two Numbers

#include<stdio.h>
int main()
{
 int a,b,hcf,lcm,max,min,r;

 printf("Enter two numbers:");
 scanf("%d%d",&a,&b);    
 if(a>b)
  {
   max=a;
   min=b;
  }
   else
    if(b>a)
    {
     max=b;
     min=a;
    }    
    if(a==b)
     hcf=a;
    else
    {
     do
     {
      r=max%min;
      max=min;
      min=r;
     }
     while(r!=0);        
      hcf=max;
   }    
   lcm=(a*b)/hcf;    
   printf(" LCM=%d HCF=%d",lcm,hcf);
   return 0;
}

Output

Enter two numbers:4  7
LCM=28
HCF=1
 

Explanation

In this program we have find the LCM and HCF of the number.






You may also like: