Chapter 14: Problem 12
include
Chapter 14: Problem 12
include
All the tools & learning materials you need for study success - in one app.
Get started for freeWrite an iterative version of the function defined in Self-Test Exercise 2 .
Write a recursive void function that has one parameter which is a positive integer and that writes out that number of asterisks '*' to the screen all on one line.
Redefine the function power so that it also works for negative exponents. In order to do this you will also have to change the type of the value returned to double. The function declaration and header comment for the redefined version of power is as follows: double power \((\text { int } x, \text { int } n)\) //Precondition: If \(n<\theta\), then \(x\) is not \(\theta\) //Returns \(x\) to the power \(n\) Hint: \(x^{-\mathrm{n}}\) is equal to \(1 /\left(x^{\mathrm{n}}\right)\)
Write a recursive function definition for the following function: int squares(int n); //Precondition: n >= 1 //Returns the sum of the squares of numbers 1 through n. For example, squares (3) returns 14 because \(1^{2}+2^{2}+3^{2}\) is 14
Write a recursive void function that has one parameter, which is a positive integer. When called, the function writes its argument to the screen backward. That is, if the argument is \(1234,\) it outputs the following to the screen: 4321
What do you think about this solution?
We value your feedback to improve our textbook solutions.