Assignment 20
Due: Monday, April 9
Reading
Continue reading Chapter 12: "JavaScript/JScript: Arrays" in Deitel, Deitel & Nieto, Internet & World Wide Web: How to Program.
Read Chapter 8 "The Gate Comes Down" in Freiberger and Swaine, Fire in the Valley: The Making of the Personal Computer.
Programming Exercises
Hand in on Monday
1) Write a recursive function power( base, exponent) that when invoked returns
baseexponent
Thus, for example, power(3,4) = 34 = 3*3*3*3 = 81. You may assume that exponent is an integer greater than or equal to 1. (Hint: the recursive step can use the relationship
baseexponent = base * baseexponent-1
and the terminating condition occurs when exponent is equal to 1 since base1 = base.
[ Note: In Lecture 18, we discussed how to create an iterative function which accomplishes the same task; see our JavaScript program power.html. In this exercise, we want you to use recursion. ]
2) Complete Exercise 11.29 on Page 383
of Deitel, Deitel and Nieto.[Note: You will subsequently be asked to modify
your program to incorporate the features discussed in Exercises 11.30 and
11.31. If you have some extra time, you may wish to start on these embellishments
now. ]
3) Write a recursive function which takes an integer value and returns the number with the digits reversed. For example, given the number 13452, the function should return 25431. Incorporate the function into a script that prompts a value from the user. The script should be able to handle an integer with any number of digits (including one). The user simply inputs the number; the user is not asked to tell the program how many digits are in the number.