Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save sheetal369/22fe8640e9b8e5fba4753c453eaff0ce to your computer and use it in GitHub Desktop.

Select an option

Save sheetal369/22fe8640e9b8e5fba4753c453eaff0ce to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int rem, quot ;
int hcf (int, int) ;
int main()
{
cout << "Input two numbers : ";
int a, b, num1, num2, hcf_num ;
/* cin >> a, b ; //USING COMMA IS A SYNTAX ERROR */
cin >> a >> b;
//for assigning max value to num1 and min value to num2
if (a>b)
{
num1 = a;
num2 = b;
}
else {
num1 = b;
num2 = a;
}
hcf_num = hcf(num1, num2) ;
cout << "\nUsing EUCLIDEAN Algorithm \nGreatest Common Divisor (GCD) is : "<<hcf_num ;
cout << endl;
return 0;
}
int i = 0 ;
int hcf(int c, int d)
{ int e, f;
static int num1[50], num2[50], quot[50], rem[50] ;
num1[i] = c;
num2[i] = d ;
quot[i] = num1[i]/num2[i];
rem[i] = num1[i]%num2[i];
e = rem[i];
f = num2[i] ;
if (e != 0)
{
i ++ ;
hcf(f, e); //Using function RECURSIVELY [You can use looping instead]
}
else {
cout << "\n------Process-------\n" ;
int j ;
for (j = 0 ; j<=i; j++)
{
cout <<num1[j] << " = "<< num2[j] << " * " << quot[j] << " + "<< rem[j] << endl;
}
return f;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment