Hcf and Lcm Of Two No.

//Hcf and Lcm.

#include<stdio.h>
main()
{
 int a,b,c,lcm,i;
 printf("enter two no\n");
 scanf("%d%d",&a,&b);
 if(a>b)
 c=b;
 else
 c=a;
 for(i=c;i>=1;i--)
 {
  if(a%i==0&&b%i==0)
 {
  printf("\nHCF of %d and %d is : %d",a,b,i);
  break;
 }
 }
 lcm=a*b/i;
 printf("\nLCM of %d and %d is : %d",a,b,lcm);
 
}

No comments:

Post a Comment