Thursday, 8 December 2016

Program to find HCF of 2 nos.

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

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...