Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
5th Edition
ISBN: 9780134801155
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 13, Problem 5PE
Program Plan Intro
Recursive Power Method
Program Plan:
- Global variable declaration:
- Initialize the variable “minimum” as “1”.
- Initialize the variable “maximum” as “100”.
- Define the “main()” function:
- Initialize the variable “number” is “0”.
- Initialize the variable “exp” is “0”.
- Get the input from the user and store it to the variable “number”.
- Check the value of “exp”
- If it is less than “minimum” or greater than “maximum”, then get the exponent “exp” from user.
- Call the function “recursivePower()” and pass the two arguments “number” and “exp”.
- Display the result on the output screen.
- Define the “recursivePower(x, y)” function:
- Check the value of “y”
- If it is equal to “0”, then returns “1”.
- Otherwise, call the function “recursivePower()” recursively along with the arguments “x” and the decremented value of “y”.
- Display the result on the output screen.
- Check the value of “y”
- Call the “main()” function.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Recursive Power FunctionWrite a function that uses recursion to raise a number to a power. The function should accept two arguments: the number to be raised and the exponent. Assume that the exponent is a nonnegative integer. Demonstrate the function in a program.
SAMPLE RUN #0: ./recursiveExponent
Hide Invisibles
Highlight: Show Highlighted Only
2^3=8↵ 2^4=16↵ 3^3=27↵ 6^3=216↵ 7^7=823543↵ 10^9=1000000000↵
he function drawFractalLine is recursive.
Write a script that draws the Koch snowflake.
Define a function main that will draw a Koch snowflake with the following parameters when the program is run:
Width = 200
Height = 200
Size = 150
Level = 4
Python Language
Prime funcation
Chapter 13 Solutions
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Ch. 13.2 - It is said that a recursive algorithm has more...Ch. 13.2 - Prob. 13.2CPCh. 13.2 - What is a recursive case?Ch. 13.2 - What causes a recursive algorithm to stop calling...Ch. 13.2 - What is direct recursion? What is indirect...Ch. 13 - Prob. 1MCCh. 13 - A module is called once from a programs main...Ch. 13 - The part of a problem that can be solved without...Ch. 13 - Prob. 4MCCh. 13 - Prob. 5MC
Ch. 13 - Prob. 6MCCh. 13 - Any problem that can be solved recursively can...Ch. 13 - Actions taken by the computer when a module is...Ch. 13 - A recursive algorithm must _______ in the...Ch. 13 - A recursive algorithm must _____ in the base case....Ch. 13 - An algorithm that uses a loop will usually run...Ch. 13 - Some problems can be solved through recursion...Ch. 13 - It is not necessary to have a base case in all...Ch. 13 - In the base case, a recursive method calls itself...Ch. 13 - In Program 13-2, presented earlier in this...Ch. 13 - In this chapter, the rules given for calculating...Ch. 13 - Is recursion ever required to solve a problem?...Ch. 13 - When recursion is used to solve a problem, why...Ch. 13 - How is a problem usually reduced with a recursive...Ch. 13 - What will the following program display? Module...Ch. 13 - What will the following program display? Module...Ch. 13 - The following module uses a loop. Rewrite it as a...Ch. 13 - Prob. 1PECh. 13 - Prob. 2PECh. 13 - Recursive Array Sum Design a function that accepts...Ch. 13 - Prob. 4PECh. 13 - Prob. 5PECh. 13 - Ackermanns Function 7. Ackermanns Function is a...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- JAVA CODE ONLY AND PROVIDE OUTPUT SCREENSHOT PLEASEarrow_forwardQuestion 1 Not complete Marked out of 1.00 Flag question Write a recursive function named count_non_digits (word) which takes a string as a parameter and returns the number of non-digits in the parameter string. The function should return 0 if the parameter string contains only digits. Note: you may not use loops of any kind. You must use recursion to solve this problem. You can assume that the parameter string is not empty. For example: Test Result print(count_non_digits ('123')) print(count_non_digits ('2rPTy5')) print(count_non_digits ('hello world')) 11 Precheck Check 0 4 Answer: (penalty regime: 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 %) 1arrow_forwardConsider the following pseudo code, Method func() { PRINT “This is recursive function" func() } Method main( { func() } What will happen when the above snippet is executed?arrow_forward
- MULTIPLE FUNCTIONS AND RECURSIVE FUNCTIONS .arrow_forwardWhen all the statements are executed before calling the function, the calling comes at the end of code lines, this called: O a. Head recursion O b. Endless recursion Recursive call O d. Tail recursionarrow_forwardRecursive function: Writing the recursive case. Write code to complete PrintFactorial()'s recursive case. Sample output if input is 5: 5! = 5 * 4 * 3 * 2 * 1 = 120 #include <stdio.h> void PrintFactorial(int factCounter, int factValue){int nextCounter;int nextValue; if (factCounter == 0) { // Base case: 0! = 1printf("1\n");}else if (factCounter == 1) { // Base case: Print 1 and resultprintf("%d = %d\n", factCounter, factValue);}else { // Recursive caseprintf("%d * ", factCounter);nextCounter = factCounter - 1;nextValue = nextCounter * factValue; /* Your solution goes here */ }} int main(void) {int userVal; scanf("%d", &userVal);printf("%d! = ", userVal);PrintFactorial(userVal, userVal); return 0;}arrow_forward
- Magic Number of coding-:A number is said to be a magic number,if summing the digits of the number and then recursively repeating this process for the given sumuntill the number becomes a single digit number equal to 1. Example: Number = 50113 => 5+0+1+1+3=10 => 1+0=1 [This is a Magic Number] Number = 1234 => 1+2+3+4=10 => 1+0=1 [This is a Magic Number] Number = 199 => 1+9+9=19 => 1+9=10 => 1+0=1 [This is a Magic Number] Number = 111 => 1+1+1=3 [This is NOT a Magic Number].arrow_forwardMULTIPLE FUNCTIONS AND RECURSIVE FUNCTIONS Use #include<stdio.h>arrow_forwardrecursion QUESTION 2 Which statement is TRUE? O A function declared with void, received values and return values. local variable is declared outside the body of functions. A function call must have a matching argument list with function definition parameter list. If a function is specified with return type the function must not contain a return statement. OUESTION 3 Click Save and Submit to save and submit. Click Save All Answers to save all answers. 252arrow_forward
- I just need exactly what they are asking me to do. Thank youarrow_forwardCodeWorkout Gym Course Search exercises... Q Search kola shreya@columbus X275: Recursion Programming Exercise: Check Palindrome X275: Recursion Programming Exercise: Check Palindrome Write a recursive function named checkPalindrome that takes a string as input, and returns true if the string is a palindrome and false if it is not a palindrome. A string is a palindrome if it reads the same forwards or backwards. Recall that str.charAt(a) will return the character at position a in str. str.substring(a) will return the substring of str from position a to the end of str,while str.substring(a, b) will return the substring of str starting at position a and continuing to (but not including) the character at position b. Examples: checkPalindrome ("madam") -> true Your Answer: 1 public boolean checkPalindrome (String s) { 4 CodeWorkout © Virginia Tech About License Privacy Contactarrow_forwardPython Test Program: import recursive_functionsimport mathdef main():# Test factorialprint('Testing factorial.')assert recursive_functions.factorial(0) == 1assert recursive_functions.factorial(1) == math.factorial(1) == 1assert recursive_functions.factorial(2) == math.factorial(2) == 2assert recursive_functions.factorial(5) == math.factorial(5) == 120assert recursive_functions.factorial(7) == math.factorial(7) == 5040print('All tests pass for `factorial` ()\n')# Test sum_recursivelyprint('Testing sum_recursively.')assert recursive_functions.sum_recursively(0) == 0assert recursive_functions.sum_recursively(1) == sum(range(1+1)) == 1assert recursive_functions.sum_recursively(2) == sum(range(2+1)) == 3assert recursive_functions.sum_recursively(10) == sum(range(10+1)) == 55print('All tests pass for `sum_recursively` () ')# Test sumlist_recursively(l)print('Testing sumlist_recursively.')assert recursive_functions.sumlist_recursively([1,2,3]) == sum([1,2,3])assert…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