Question: CSC 2 2 2 Module 4 Coding Assignment - Recursion Write a program that uses a recursive call to find the integer logk of a

CSC 222 Module 4 Coding Assignment - Recursion
Write a program that uses a recursive call to find the integer logk of a number. Where logk, returns the integer log of a number in a designated base. For example, the integer base 10log of 1234 is 3, and the integer base 2log of 1234 is 10. This is a relatively easy calculation. You simply repeatedly divide the number by the base using integer division until the quotient is less than the base and count the number of completed divisions.
123410=123(1)
12310=12(2)
1210=1(3)
12342=617(1)
6172=308(2)
3082=154(3)
1542=77(4)
772=38(5)
382=19(6)
192=9(7)
92=4(8)
42=2(9)
22=1(10)
Notice that the number 1234 is actually 1103+2102+3101+4100 and in base 2 the number 1234 would be 1210+029+028+127+126+025+124+023+022+121+020
The key point here is that the highest power in these numbers in the integer log value.
Hint use the number and the base as arguments to your recursive call, then your base case is when number is less than base and returns 0, and the general case returns 1 plus the returned value of the recursive call.
Your program should behave as follows.
Please enter a number to find the integer log of 1234
Please enter the base for the calculation
2
The base 2 integer log of 1234 is 10
Would you like to enter another pair of numbers?
Please enter " y " for yes or " n " for no.
b
Please enter " y " for yes or " n " for no.
y
Please enter a number to find the integer log of
1
1234
Please enter the base for the calculation
5
The base 5 integer log of 1234 is 4
Would you like to enter another pair of numbers?
Please enter " y " for yes or " n " for no.
n
Good-bye!
Mobile View
Read Aloud
Headings
CSC 2 2 2 Module 4 Coding Assignment - Recursion

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 Programming Questions!