C Program to calculate LCM and HCF/GCD of two numbers



#include 

int LCM (int ,int);

int HCF (int ,int);

int main(){
 int a,b,L,H;
 printf("enter two numbers\n");
 scanf ("%d%d",&a,&b);
 L=LCM(a,b);
 H=HCF(a,b);
 printf("LCM is %d and HCF is %d",L,H);
 return 0;
}

int LCM (int x, int y){
 int L;
 for (L=1;L<=x*y;L++)
  if (L%x==0 && L%y==0)
   break;
  return (L);
}

int HCF (int x, int y){
 int H;
 for (H=(x=1;H--)
  if (x%H==0 && y%H==0)
   break;
  return (H);
}

No comments:

Post a Comment