Challenge: GCD of Two Real Numbers Using the Trailing <requires>

Try to find the GCD of two real numbers using the trailing <requires> clause.

Problem

Write a function that takes two real numbers as parameters and returns the GCD of two numbers.

Restriction

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

Input

Two floating numbers a and b, as shown below

a = 0.3, b = 0.9

Output

A real number, as shown below.

0.3

Sample main function

int main()
{
    std::cout<<gcd(0.3,0.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.