Question: int modulus (number, base) { The modulus operation returns the unit value of a number in a given base. For example: In base 10 ,

 int modulus (number, base) { The modulus operation returns the unit

int modulus (number, base)

{

The modulus operation returns the unit value of a number in a given base. For example: In base 10 , the unit value of 237 is 7.(237%10=7) In base 2 , the unit value of 1023 is 1 . (1023%2=1) In base 8 , the unit value of 6 is 6.(6%8=6) Write a recursive function in that will calculate the modulus of two positive inputs (the number and the base). Note: you may only use addition and subtraction - you must not use multiplication, division, modulus, or any other methods in your solution, and you will not receive any credit for a non-recursive solution. Hint: use repeated subtraction. For example, the following statements would lead to the underlined output: Example 1: print(modulus(237,10));7 Example 2: print(modulus(1023,2));1 Example 3: print(modulus(6,8));6 Note: you may assume two positive inputs - no error checking of inputs is required

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!