Skip to content

Instantly share code, notes, and snippets.

@rahularity
Last active July 24, 2020 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahularity/8c9089a09e7d45d6b78229893544fc88 to your computer and use it in GitHub Desktop.
Save rahularity/8c9089a09e7d45d6b78229893544fc88 to your computer and use it in GitHub Desktop.
Midnight Code: learn before you sleep. (DAY 1)
/*
	===================== GCD (GREATEST COMMON DIVISOR) =====================
	
	FINDING THE GREATEST COMMON DIVISOR EFFICIENTLY USING EUCLID'S FORMULA.
				GCD(a,b) = GCD(b, a%b)
	
*/

int GCD (int a, int b){
    // base case
    if(b == 0)
         return a;
  
    return (b, a%b);
}


int main() {
	int a = 7;
	int b = 21;
	
	cout << GCD(a,b);
	
	return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment