Question: Write the following program in c++: Each function in your program should have a header comment as well. Describe its purpose, the parameters and the
Write the following program in c++: Each function in your program should have a header comment as well. Describe its purpose, the parameters and the return value (if any). Use a format similar to:
// Function name:
// Purpose:
// Parameters:
// Return value
The Greatest Common Divisor (gcd) of two or more integers, when at least one of them is not zero, is the largest positive integer that divides the numbers without a remainder. For example, the GCD of 8 and 12 is 4. Write a function named calc_gcd that takes two positive integer arguments and returns the greatest common divisor of those two integers. If the function is passed an argument that is not greater than Zero, then the function should return the value -1 to indicate that an error occurred.
For example,
cout << calc_gcd (8,12) ; // will print 4
cout << calc_gcd(256,625) ; // will print 1
cout << calc_gcd (0,8) ; // will print -1
cout << calc_gcd (10,-2) ; // will print -1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
