Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 14.1, Problem 5STE
Program Plan Intro
Recursive function:
- Recursive function is a function that call itself.
- A function definition may have a call to the function being defined. In such cases, the function is known as recursive.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a function which takes two integer parameters for values to be added together
and returns the result by value. The function may not print anything or read anything
directly from the user (i.e. no cin/cout in the function). Assume that the values passed
to the function will not be negative, but could be 0 or positive, and will both be integers.
The function must implement addition recursively, and cannot use the standalone +
operator (only ++) or call any other functions.
Write a recursive void function that has one parameter that 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.
I've literally tried to create this program and I have no idea how to make it work. Please help me. Is it possible to explain line by line what the code does?
Write an iterative version of the function defined in Self-Test Exercise 2.
(Write a recursive void function that has one parameter that is a positive integer and that writes out that number of asterisks (*) to the screen, all on one line.)
Chapter 14 Solutions
Problem Solving with C++ (10th Edition)
Ch. 14.1 - Prob. 1STECh. 14.1 - Prob. 2STECh. 14.1 - Prob. 3STECh. 14.1 - Prob. 4STECh. 14.1 - Prob. 5STECh. 14.1 - If your program produces an error message that...Ch. 14.1 - Write an iterative version of the function cheers...Ch. 14.1 - Write an iterative version of the function defined...Ch. 14.1 - Prob. 9STECh. 14.1 - Trace the recursive solution you made to Self-Test...
Ch. 14.1 - Trace the recursive solution you made to Self-Test...Ch. 14.2 - What is the output of the following program?...Ch. 14.2 - Prob. 13STECh. 14.2 - Redefine the function power so that it also works...Ch. 14.3 - Prob. 15STECh. 14.3 - Write an iterative version of the one-argument...Ch. 14 - Prob. 1PCh. 14 - Prob. 2PCh. 14 - Write a recursive version of the search function...Ch. 14 - Prob. 4PCh. 14 - Prob. 5PCh. 14 - The formula for computing the number of ways of...Ch. 14 - Write a recursive function that has an argument...Ch. 14 - Prob. 3PPCh. 14 - Prob. 4PPCh. 14 - Prob. 5PPCh. 14 - The game of Jump It consists of a board with n...Ch. 14 - Prob. 7PPCh. 14 - Prob. 8PP
Knowledge Booster
Similar questions
- Provide JAVA source code with proper comments for attached assginment.arrow_forwardWrite a recursive function that takes as a parameter a nonnegative integer and generates the following pattern of stars. If the nonnegative integer is 4, the pattern generated is as follows: **** *** ** * * ** *** **** Also, write a program that prompts the user to enter the number of lines in the pattern and uses the recursive function to generate the pattern. For example, specifying 4 as the number of lines generates the preceding pattern.arrow_forwardQuestion 2: Implementing a Recursive Function .Write recursive function, recursionprob(n), which takes a positive number as its argument and returns the output as shown below. The solution should clearly write the steps as shown in an example in slide number 59 and slide number 60 in lecture slides. After writing the steps, trace the function for “recursiveprob(5)” as shown in an example slide number 61. Function Output: >> recursionprob(1) 1 >> recursionprob(2) 1 4 >> recursionprob(3) 1 4 9 >>recrusionprob(4) 1 4 9 16arrow_forward
- Write a recursive function called draw_triangle() that outputs lines of '*' to form a right side up isosceles triangle. Function draw_triangle() has one parameter, an integer representing the base length of the triangle. Assume the base length is always odd and less than 20. Output 9 spaces before the first '*' on the first line for correct formatting. Hint: The number of '*' increases by 2 for every line drawn. Ex: If the input of the program is: 3 the function draw_triangle() outputs: * *** Ex: If the input of the program is: 19 the function draw_triangle() outputs: * *** ***** ******* ********* *********** ************* *************** ***************** ******************* Note: No space is output before the first '*' on the last line when the base length is 19. if __name__ == '__main__': base_length = int(input()) draw_triangle(base_length)arrow_forward1) Write a recursive void function that has one parameter that is a positive integer and that writes out that number of asterisks (*) to the screen, all on one line. How do I do this in python?arrow_forwardlanguage: Python Problem: Write a recursive function reverse(sentence) for reversing a sentence. For example, reverse('Who let the dogs out?') will return '?tuo sgod eht tel ohW'. Also write a test case in the program to prove the function given works.arrow_forward
- Need python help. For problems 1 and 2, add your code to the file Lab2.java. Add your tests in the main function of Lab2.java. Do not use static variables in class Lab2 to implement recursive methods. Problem 1: Implement a recursive method min that accepts an array and returns the minimum element in the array. The recursive step should divide the array into two halves and find the minimum in each half. The program should run in O(n) time and consume O(logn) memory. Demonstrate the output of min on the array int [] a = { 2, 3, 5, 7, 11, 13, 17, 19, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 23, 29, 31, 37, 41, 43 } Problem 2 You have been offered a job that pays as follows: On the first day, you are paid 1 cent, on the second day, 2 cents, on the third day, 4 cents and so on. In other words, your pay doubles every day. Write a recursive method computePay that for a given day number computes the pay in cents. Assume that you accumulate all the money that you are paid. Write a…arrow_forward‘Write a function nesting(), which takes an arbitrary number of parameters, and returns a list containing the arguments. Write another function unnesting(), which takes a list L as the parameter and retums a 1D list. Notice that, you should be able to use loops to solve thisproblem and should not use recursive functions (which we will not cover in this course). ‘Write assertions to test the two functions.For example nesting(1, nesting(2, 3, nesting(4, 5, [6])), [7, 8], 9)unnesting([1, [2, 3, [4, 5, [6]]], [7. 8], 9]) (1, [2, 3, [4, 5, [6]]], [7, 8], 9][1, 2,3, 4, 5, 6, 7, 8 9]arrow_forwardProvide Complete code , please don't spam itarrow_forward
- Write a recursive function that returns true if the digits of a positive integer are in increasing order; otherwise, the function returns false. Also, write a program to test your function.arrow_forwardHi can check my code below and see whether it has meet the following, if not kindly assist and correct it for me. a). Recursive function in Java that accepts an integer as input and returns 1 + 1/2 + 3 + 1/4 + ...(n or 1/n). b). The answer is the sum of the odd integers from 1 to n plus the sum of the reciprocals of the even integers. Thank you. public class Main {public static double sum(int n) {if (n <= 0) {return 0;} else if (n % 2 == 0) {return 1.0 / n + sum(n - 1);} else {return n + sum(n - 1);}}public static void main(String[] args) {System.out.println(sum(5));}}arrow_forwardImplement a recursive function called evens that returns an integer with only theeven numbers. Note this function is returning an integer, not printing. There shouldbe no use of cout within your function. The function declaration should look asfollows:int evens(int n);(ex. evens(234567); returns 246)(ex. cout << evens(56032); prints 602)arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning