Program to find Greatest common divisor of two numbers.(HCF)

source code:


#include <iostream>
#include<conio.h>
#include<iomanip>
using namespace std;

int main()
{
cout<<"Enter two numbers to find their greatest common divisor : "<<endl<<endl;
int a,b ,i=1,ans;
cin>>a>>b;cout<<"\n\n\n\n\n";


while(i<a)
{
   if((a%i==0)&&(b%i==0))
         ans=i;
   i++;
}
cout<<"GCD is "<<ans;
getch();
}

Leave a comment