My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

find hcf using function

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
int hcf(int,int);
void main()
{ clrscr();
  int a,b;
  cout<<"enter the numbers:";
  cin>>a>>b;
  cout<<"HCF of two number is:"<<hcf(a,b);
  getch();
}
 int hcf(int x,int y)
 {
  if(x>y)
  { for(int i=y;i>0;i--)
    { if(x%i==0&&y%i==0)
       return i;
    }
  }
  else
   for(int i=x;i>0;i--)
    { if(x%i==0&&y%i==0)
      return i;
    }
}

0 comments: