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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s