Question: Write a function named computeGCD that takes two positive integer arguments and returns the greatest common divisor of those two integers. If the function is

Write a function named computeGCD 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 than an error occurred. For instance,

(THE COUT IS JUST AN EXAMPLE FOR THE GENERAL FORMAT. THE HOMEWORK PROBLEM SPECIFIES THAT YOU WRITE A FUNCTION NAMED GCD THAT TAKES TWO INTERGERS INPUTED BY THE USER AND TAKES THE GREATEST COMMON DIVISOR FROM THEM. DO NOT JUST USE THE EXAMPLE AS THE FUNCTION.) [4] cout << computeGCD(8, 12); // output: 4 cout << computeGCD(256, 625); // output: 1 cout << computeGCD(0, 8); // output: -1 cout << computeGCD(10, -2); // output: -1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!