Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 14, Problem 1PC
Program Plan Intro
Iterative Factorial
Program Plan:
- Include the required header files.
- Declare the necessary function prototype and constants.
- Define the “main()” function.
- Declare the variable “value” for storing the number.
- Get the input from the user.
- Call the method “calfactorial()” to compute the factorial of the given number.
- Computed result gets displayed.
- Define the “calfactorial()” method
- Declare the necessary variables.
- Use loop to iterate and compute the factorial of the given number.
- Return the value after computing.
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↵
Please solve it
Exponent
y Catherine Arellano
mplement a recursive function that returns
he exponent given the base and the result.
for example, if the base is 2 and the result is
3, then the output should be 3 because the
exponent needed for 2 to become 8 is 3 (i.e.
23 = 8)
nstructions:
1. In the code editor, you are provided
with a main() function that asks the
user for two integer inputs:
1. The first integer is the base
2. The second integer is the result
2. Furthermore, you are provided with the
getExponent() function. The details of
this function are the following:
1. Return type - int
2. Name - getExponent
3. Parameters
1. int - base
2. int - result
4. Description - this recursive function
returns the exponent
5. Your task is to add the base case and
the general case so it will work
Score: 0/5
Overview
1080
main.c
exponent.h
1 #include
2 #include "exponent.h"
3 int main(void) {
4
int base, result;
5
6
printf("Enter the base: ");
scanf("%d", &base);
7
8
9
printf("Enter the result: ");…
Chapter 14 Solutions
Starting Out With C++: Early Objects (10th Edition)
Ch. 14.1 - What is a recursive functions base case?Ch. 14.1 - What happens if a recursive function does not...Ch. 14.1 - Prob. 14.3CPCh. 14.1 - What is the difference between direct and indirect...Ch. 14 - What type of recursive function do you think would...Ch. 14 - Which repetition approach is less efficient; a...Ch. 14 - When should you choose a recursive algorithm over...Ch. 14 - Prob. 4RQECh. 14 - Prob. 5RQECh. 14 - Prob. 6RQE
Ch. 14 - Predict the Output 7. What is the output of the...Ch. 14 - Soft Skills 8. Programming is communication; the...Ch. 14 - Prob. 1PCCh. 14 - Recursive Conversion Convert the following...Ch. 14 - Prob. 3PCCh. 14 - Recursive Array Sum Write a function that accepts...Ch. 14 - Prob. 5PCCh. 14 - Recursive Member Test Write a recursive Boolean...Ch. 14 - Prob. 7PCCh. 14 - Prob. 8PCCh. 14 - Ackermanns Function Ackermanns function is a...Ch. 14 - Prefix to Postfix Write a program that reads...Ch. 14 - Prob. 11PCCh. 14 - Prob. 12PC
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
- (Numerical) Write a program that tests the effectiveness of the rand() library function. Start by initializing 10 counters to 0, and then generate a large number of pseudorandom integers between 0 and 9. Each time a 0 occurs, increment the variable you have designated as the zero counter; when a 1 occurs, increment the counter variable that’s keeping count of the 1s that occur; and so on. Finally, display the number of 0s, 1s, 2s, and so on that occurred and the percentage of the time they occurred.arrow_forwardJAVA CODE ONLY AND PROVIDE OUTPUT SCREENSHOT PLEASEarrow_forwardProblem Statement for Recursive Sum of Numbers Program Here is a simple recursive problem: Design a function that accepts a positive integer >= 1 and returns the sum of all the integers from 1 up to the number passed as an argument. For example, if 10 is passed as an argument, the function will return 55. Use recursion to calculate the sum. Write a second function which asks the user for the integer and displays the result of calling the function. Part 1. Understand the Problem To design a recursive function, you need to determine at least one base case (the base case returns a solution) and a general case (the general case calls the function again but passes a smaller version of the data as a parameter). To make this problem recursive think about it like this: If the integer is 1, the function will return 1. If the integer is 2, the function will return 1 + 2 = 3. If the integer is 3, the function will return 1 + 2 + 3 = 6. . . . For this problem, we will be sending in the "last"…arrow_forward
- Question 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_forwardRecursive PrintingDesign a recursive function that accepts an integer argument,n , and prints the numbers 1 up through n .arrow_forwardWrite a recursive function that finds factorial. Ex 4 >>>> 24 WRITE IN PYTHON PLEASEarrow_forward
- When 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_forwardGood Programming practices help in improving programs readability and understandability both for a programmer and for a general user. What changes would you make in the following program, written by a beginner, keeping in view the good programming practices.You are also required to write the output of the program if a user wants to find factorial of number 6.Note: The Program finds/calculates factorial of a number using a userdefined recursive function.#include<iostream> using namespace std;int f(int n);int main() {int n;cout << "Enter: "; cin >> n;cout << "Answer = " <<factorial(n);return 0;}int f(int n) {if(n > 1)return n * f(n - 1);else return 1; }arrow_forwardGood Programming practices help in improving programs readability and understandability both for a programmer and for a general user. What changes would you make in the following program, written by a beginner, keeping in view the good programming practices. You are also required to write the output of the program if a user wants to find factorial of number 6. Note: The Program finds/calculates factorial of a number using a user defined recursive function. #include<iostream> using namespace std; int f(int n); int main() { int n; cout << "Enter: "; cin >> n; cout << "Answer = " <<factorial(n); return 0; } int f(int n) { if(n > 1) return n * f(n - 1); else return 1; }arrow_forward
- Good Programming practices help in improving programs readability and understandability both for a programmer and for a general user. What changes would you make in the following program, written by a beginner, keeping in view the good programming practices.You are also required to write the output of the program if a user wants to find factorial of number 6.Note: The Program finds/calculates factorial of a number using a user defined recursive function. #include<iostream>using namespace std;int f(int n);int main(){int n;cout << "Enter: ";cin >> n;cout << "Answer = " <<factorial(n);return 0;}int f(int n){if(n > 1)return n * f(n - 1);elsereturn 1;}arrow_forwardC PROGRAMarrow_forward7. Recursive Power Method In Python, design 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 the exponent is a nonnegative integer.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 LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr