Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ The Greatest Common Divisor (gcd) of two or more (consider only positive non-zero) integers is the largest positive integer that divides the numbers without

C++ The Greatest Common Divisor (gcd) of two or more (consider only positive non-zero) integers is the largest positive integer that divides the numbers without a remainder. For instance, the GCD of 8 and 12 is 4. Write a function named computeGCD that takes two user inputted 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:

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions

Question

Factors Affecting Conflict

Answered: 1 week ago