Challenge 1: Find the Greatest Common Divisor
Given two numbers, find their greatest common divisor.
We'll cover the following
Problem Statement
Implement a function that takes two numbers, testVariable1
and testVariable2
and returns their greatest common divisor.
What is the Greatest Common Divisor?
The Greatest Common Divisor of two or more integers is the largest positive integer that divides each of the integers.
For example, take two numbers and .
can be completely divided by , , , , , , and .
can be completely divided by , , , , , , and .
Therefore the greatest common divisor of and is .
Input
Two variables testVariable1
and testVariable2
containing numbers.
Output
The greatest common divisor of testVariable1
and testVariable2
.
Sample Input
6, 9
Sample Output
3
Try it Yourself
Try this challenge yourself before moving on to the solution. Good luck!
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.