Chapter 14: Problem 8
Write an iterative version of the function defined in Self-Test Exercise 2 .
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.
/*! This file is auto-generated */ .wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none}
Learning Materials
Features
Discover
Chapter 14: Problem 8
Write an iterative version of the function defined in Self-Test Exercise 2 .
These are the key concepts you need to understand to accurately answer the question.
All the tools & learning materials you need for study success - in one app.
Get started for free
Write a recursive void function that takes a single int argument \(n\) and writes the integers \(1,2, \ldots, n\)
Write a recursive void function that takes a single int argument \(n\) and writes integers \(n, n-1, \ldots, 3,2,1 .\) Hint: Notice that you can get from the code for Self-Test Exercise 4 to that for Self-Test Exercise 5 (or vice versa) by an exchange of as little as two lines.
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 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.
include
What do you think about this solution?
We value your feedback to improve our textbook solutions.