Followers

Thursday, March 15, 2012

HCF


#include<iostream.h>
#include<conio.h>
int n1, n2, a, hcf;
void main()
{
  cout<<"Enter two numbers : ";
  cin>>n1>>n2;
  if(n1<n2)
    a=n1;
  else
    a=n2;
  for(int i=a; i>=1 ; i--)
  {
    if(n1%i==0 && n2%i==0)
    {
      hcf=i;
      break;
    }
  }
  cout<<"\nHCF = "<<hcf;
  getch();
}
.................................................................
OUTPUT :(click to enlarge the image)

1 comment: