Skip to content

Latest commit

 

History

History
66 lines (41 loc) · 994 Bytes

File metadata and controls

66 lines (41 loc) · 994 Bytes

Recursion Exercises

1. Find the factorial of a given number (review)
Factorial definition:

5 factorial = 5! = 5 * 4 * 3 * 2 * 1 = 120



2. Print out all elements in an array recursively



3. Concatenate all the elements in an array of Strings

Sample Input: ["Hi", "there", ",", " ", "user","!"]

Sample Output: "Hi there, user!"



4. Find the sum of all the numbers in an array

Sample Input: [3,6,1,3,2]

Sample Output: 15



5. Find the sum of all the even numbers in an array

Sample Input: [3,6,1,3,2, 10]

Sample Output: 18



6. Multiply two given Ints.  Do not use for/while loops or the * operator.

Sample Input: 5 * 6

Sample Output: 30



7. Write a recursive function pow that takes two numbers x and y as input and returns x to the power y.  Do not use for/while loops

Sample Input: 3 ^ 4

Sample Output: 81