Write a function no_zeroes(n) that takes an integer n and returns an integer formed by removing all zeroes from the end of n's decimal representation. For example:
no_zeroes(54000) = 54
no_zeroes(2256) = 2256
As a special case, no_zeroes(0) = 0.
You may not use any loops in your solution, so you will need to write the function recursively.
a) Write a recursive function is_pow_of_2(n)
that returns True if
n is a power of 2.
b) Generalize the function: write a recursive function is_pow_of_k(k, n) that returns True if n is a power of k.
Write a function sum(a, i, j) that computes the sum of the values in the range a[i:j]. You may not use any loops or call the built-in sum() function, so you will need to use recursion.
Write a function max(a, i, j) that computes the maximum value in the range a[i:j]. You may not use any loops or call the built-in max() function, so you will need to use recursion.
Write a function search(a, x) that takes a sorted array a and a value x to search for in the array. It should return True if x is present in the array, otherwise false. Use a binary search. Do not use any loops; instead, write a recursive helper function.
Write
a recursive function mul(a,
b)
that
returns the product (a * b) for positive integers a and b. You may
use the built-in addition operator (+), but not the multiplication
operator (*).
Use
recursion to write a function same_as_first(a)
that
returns the number of integers in an array a that are equal to its
first element.