Change Figure 11.2s recursive Factorial program so that it uses tail recursion. Figure 11.2 1234 4 5
Question:
Change Figure 11.2’s recursive Factorial program so that it uses tail recursion.
Figure 11.2
Transcribed Image Text:
1234 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 import java.util.Scanner; public class Factorial { public static void main(String[] args) ( Scanner stdIn = new Scanner(System.in); int num; System.out.print("Enter a non negative number: "); num= stdin.nextInt(); if (num > 0) ( System.out.println(factorial(num)); } } // end main //** private static int factorial (int n) { int nF; // n factorial if (n C == nF - 1; } else { 1 || n - 0) nFn factorial(n-1); } return nF; } // end factorial } // end Factorial class Sample session: Enter a nonnegative number: 5 120 stopping condition recursive method call
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (1 review)
In the provided Java code for calculating factorial the recursion is not in the tailrecursive form A ...View the full answer
Answered By
Rohith Bellamkonda
I am studying in IIT Indore,the most prestigious institute of India.I love solving maths and enjoy coding
5.00+
1+ Reviews
10+ Question Solved
Related Book For
Introduction To Programming With Java A Problem Solving Approach
ISBN: 9781260575248
3rd International Edition
Authors: John Dean
Question Posted:
Students also viewed these Computer science questions
-
Modify the previous exercises Recurse program so that it uses tail recursion. Minimize code changes. You should be able to do this with exactly the same number and sequence of statements and with...
-
1. Derive the intensity of diffracted beam for a set of triple-slit shown below, and plot the result for the cases of (a) a= 2b and c= 3a and (b) a = 6band c= 32a. b- 000 Pat D Where D>>a, c>b, D is...
-
In this exercise, you modify the program from Computer Exercise 31. The modified program will allow the user to change the grading scale while the program is running. If necessary, create a new...
-
Smart Price Company, a producer of black forest cakes, has budgeted sales and production (in units) for the last quarter in 2019 to be as follows: Sales Production October November 26,000 28,000...
-
What happens if you attempt to insert the record (Perryridge, A-929, 3000) into the file of as shownbelow? A-201 A-218 Perryridge Round Hill Mianus A-102 400 900 700 A-305 350 A-215 700 A-101 600...
-
The generator polynomial of a (15, 11 Hamming code is defined by g(X) = 1 + X + X4 develop the encoder and syndrome calculator for this code, using a systematic form for the code.
-
Use Exercise 10.13 or other software to obtain the interval requested in Exercise 10.3. Data From Exercise 10.13 10.13 MINITAB determination of confidence interval for p When the sample size is not...
-
The following employees of Memory Bytes of Titusville, Washington, are paid in different frequencies. Some employees have union dues and/or garnishments deducted from their pay. Calculate their net...
-
Concord Corporation is analyzing its account balances for 2022. As of the end of 2022, a debit balance of $4500 remains in the Manufacturing Overhead account. What impact will this have on the...
-
A palindrome is a string that reads the same in both directions. For example, mom, kayak, and avid diva are all palindromes. Write a recursive method named isPalindrome that determines whether a...
-
Modify the previous exercises program so that it uses iteration instead of recursion. Do not use an array. Exercise 11.5: Modify the previous exercises Recurse program so that it uses tail recursion....
-
Tough Fiber Company is the creator of Y-Go, a technology that weaves silver into its fabrics to kill bacteria and odor on clothing while managing heat. Y-Go has become very popular as an undergarment...
-
What are the shortcomings of the expectations theory?
-
What are restrictive covenants? Why do investors introduce restrictive covenants into bond contracts?
-
Distinguish between the profit distribution for common stockholders and for preferred stockholders.
-
What is the relationship between a corporation and a stockholder?
-
Explain how incentive contracts help to reduce the problem of moral hazard.
-
What is the purpose of the weighted alternative matrix? Describe its typical content.
-
3.16. For a system with non-identical service rates (see Sect. 3.5) and a limit of N jobs in the system (Eq. 3.13), obtain an expression for the mean service time per job, E[Ts], as a function of the...
-
You and your team get a distress call from another ship indicating that there has been an explosion and their propulsion and navigation systems are now off line. A large piece of their ship has been...
-
Consider a one-particle, one-dimensional system with And V = ( elsewhere. V0 and c are constants and 0 ( c ( 0.25. (a) Take the unperturbed system as a particle in a one-dimensional box and find E(1)...
-
Drawing on data from the closing case study of chapter 3 about the music and on work you have already done, produce a critical summary of EMIs resources and capabilities using the VRIOS format of...
-
1.Dependable Service Industries (DSI) has a WACC of 15%. DSI is considering two projects, code named P100 and P200. Bill, DSI's financial manager, estimates the internal rate of return on these...
-
What does a cash flow budget tell a manager about the projected profitability of the business?
-
Watergate has a beta of 1.25. The market risk premium is 10% and the risk-free rate is 2.5%. ABC Corp. has 1 million outstanding bonds trading at $100 currently. ABC Corp. has 20 million shares...
Study smarter with the SolutionInn App