Question: Write a program that takes two non-negative integers from standard input and calculates their greatest common divisor (gcd). Recall that the greatest common divisor of

 Write a program that takes two non-negative integers from standard input

Write a program that takes two non-negative integers from standard input and calculates their greatest common divisor (gcd). Recall that the greatest common divisor of two integers is the largest positive integer that is a divisor of both numbers. For example, the gcd of 6 and 9 is 3; the gcd of 16 and 32 is 16; and. by number theory, the gcd of 0 and a, for a = 0, 1, 2, ... is a. At the start of the program, prompt the user to input two integers by printing "Calculate GCD (A, B). Input A B: ". If either input is negative, then print "Both inputs must be non-negative. ". If both inputs are non-negative, then print their gcd as "The gcd is . ", where is replaced by your calculated gcd. As part of your program, you must make a function that takes two integer arguments and returns their gcd as an integer. You can use the following function prototype: int gcd(int a, int b); Example input/output pairs (excluding the prompt) are provided below: Input: 6 9; Output: The gcd is 3. Input: 32 16; Output: The gcd is 16. Input: 4 0; Output: The gcd is 4. Input: -1 3; Output: Both inputs must be non-negative

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!