Thursday, 8 December 2016

Program to find HCF of 2 nos. usin' Function

#include<conio.h>
#include<iostream.h>
int HCF_of(int x,int y);
void main()
{ clrscr();
  int x,y,z;
  cout<<"Enter 2 nos. ";
  cin>>x>>y;
  z=HCF_of(x,y);
  cout<<"HCF is "<<z;
  getch();
}
int HCF_of(int x,int y)
{ int a,b,c;
  a=x>y?x:y;
  b=x<y?x:y;
  for (int i=1;i<=a;i++)
      { if (a%i==0)
  { if (b%i==0)
c=i;
  }
      }
  return(c);
}

No comments:

Post a Comment

Basic Implementation of Array as a Pointer

#include<iostream.h> #include<conio.h> void main() { clrscr();   int arr[5];   cout<<"Enter 5 nos. ";   f...