Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program called gcd.c that contains a recursive function that calculates the greatest common divisor of two given integers. The function has the following

Write a program called gcd.c that contains a recursive function that calculates the greatest common divisor of two given integers. The function has the following prototype: int gcd(int m, int n);

Hint: the classic algorithm for computing the GCD, known as Euclid's algorithm, goes as follows: Let m and n be the two numbers we want to get the gcd for. If n is 0, then stop since m is the gcd. Otherwise, compute the remainder when m is divided by n . Copy n into m and copy the remainder into n . Then repeat the process, starting with testing whether n is 0. Remember that you must implement a recursive version of gcd.

Your program prompts the user to enter two integers and then outputs the gcd as follows: Enter two integers: 12 28 Greatest common divisor: 4

Files that need to be on GitHub: gcd.c Makefile to compile the program

Demo: Show your gcd function to your TA -- must be a recursive function-- (1 mark) Run make clean and then make . As usual, must not have any errors or warnings. (0.5 marks) Run your program so your TA can verify the output (0.5 marks)

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

Data Management Databases And Organizations

Authors: Watson Watson

5th Edition

0471715360, 978-0471715368

More Books

Students also viewed these Databases questions

Question

1. The evaluation results can be used to change the program.

Answered: 1 week ago

Question

5. To determine the financial benefits and costs of the program.

Answered: 1 week ago