fbpx

C++: Greatest Common Denominator

Bjarne-stroustrup
 

int Find_Greatest_Common_Denominator(int x, int y)
//Function that finds the Greatest Common Denominator ("GCD") between 2 integers
{ 
	int a;
	if(x==0)
		cout << y << endl;
	if(y==0)
		cout << x << endl;
	if(x==y)
		cout << x << endl;
	if(x>y)
	{  
		a = x - y;  
		return Find_Greatest_Common_Denominator(a, y); 
	}
	if(y>x)
	{  
		a = y - x;  
		return Find_Greatest_Common_Denominator(x, a); 
	} 
}