[SOLVED] Part 2: Compute the Greatest Common Factor Solution

15.00 $

Programming resource
Digital learning resource
Category:
Practical programming resource
Suitable for guided study and reference
Tutor guidance available when needed

Description

5/5 - (2 votes)

Write a program that computes the GCF (Greatest Common Factor) of two positive whole numbers entered by the user. For example the GCF of 24 and 18 is 6. The program will prompt the user for entering two positive whole numbers and will then return their GCF. The user may terminate the program by entering -1 for the first number. The program should provide a Tecursive function to compute GCF.

Test the above for at least 4 pairs of values. Mathematical Calculation: GCF of two whole numbers can be calculated mathematically via repeated division. For example, GCF of 16 and 26 can be found as below

1. Divide 16 into 26. The remainder is 10.

2. Divide 10 (the remainder in the last step) into 16 (the divisor in the last step). The remainder is 6.

3. Divide 6 (the remainder in the last step) into 10 (the divisor in the last step). The remainder is 4.

4. Divide 4 (the remainder in the last step) into 6 (the divisor in the last step). The remainder is 2.

5. Divide 2 (the remainder in the last step) into 4 (the divisor in the last step). The remainder is 0. Hence GCF is 2

Note: You are to provide a recursive function to implement the above algorithm.

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.