Challenge - GCD of Two Integers Using the <requires> Clause

Let’s try to solve the GCD problem by using the <requires> clause.

Problem

Write a function that takes two integer numbers as parameters and returns the greatest common divisor (GCD) of two numbers.

Restriction

We can only use a template function based on the requires clause.

Input

Two integer numbers a and b, as shown below

a = 3, b = 9

Output

A real number, as shown below.

3

Sample main function

int main()
{
    std::cout<<gcd(3,9)<<'\n';
}

Note: We don’t need to write the main function in the code below.

Challenge

Try it yourself first. If you have trouble getting to the solution, you can always press the “Show Solution” button to see how to solve the problem. We’ll go through the in-depth solution in the next lesson.

Good luck!

Get hands-on with 1200+ tech skills courses.