Question: Define a recursive function IN C++ isDivisibleBy7 that returns true if the given number is divisible by 7, and false otherwise. For example: isDivisibleBy7(1073) returns

Define a recursive function IN C++ isDivisibleBy7 that returns true if the given number is divisible by 7, and false otherwise. For example: isDivisibleBy7(1073) returns false. To find out if a number is divisible by 7, you can follow this algorithm: Remove the last digit and double it. Subtract it from the remaining number. If the result is zero or a recognizable 2-digit multiple of 7, then the number is divisible by 7. Otherwise no or repeat if more than 2 digits are left. For example: Is 1073 divisible by 7? Remove the last digit, 3, from the number and double it, which becomes 6. The remaining number becomes 107, so 107-6 = 101.

101 has 3 digits (which is more than 2), so repeating the process one more time: remove the last digit, 1, and double it, which becomes 2. Remaining number 10 2 = 8. As 8 is not divisible by 7, the number 1073 is not divisible by 7. Your function *must* be recursive and implement the above algorithm. You cannot use division or modulo to check for divisibility by 7 until you are down to a 2-digit number.

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!