Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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_2

Step: 3

blur-text-image_3

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

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions