Thursday, July 21, 2011

Program to find LCM and HCF of two no {Version 2}

/*Serial No.105     [swami82.cpp]*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,old_rem,cur_rem,new_rem,lcm,hcf;
clrscr();
printf("Enter the two no:");
scanf("%d%d",&a,&b);
if(a<b)
  {
  old_rem=b;
  cur_rem=a;
  }
  else
  {
  old_rem=a;
  cur_rem=b;
  }
do{
  new_rem=old_rem%cur_rem;
  old_rem=cur_rem;
  cur_rem=new_rem;
  }while(new_rem!=0);
hcf=old_rem;
lcm=(a*b)/hcf;
printf("LCM=%d\tHCF=%d",lcm,hcf);
getch();
}

No comments:

Post a Comment

If you have any doubt, feel free to ask...