Reference no: EM132211450
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:\n". If either input is negative, then print "Both inputs must be non-negative.\n". If both inputs are non-negative, then print their gcd as "The gcd is .\n", 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.