Question: Question 19 Consider the following function: public static int factorial(int n) { if( n == 0) return 1; else return (n-1)* factorial(n); } a) Explain

Question 19

Consider the following function:

public static int factorial(int n) {

if( n == 0) return 1; else return (n-1)* factorial(n);

}

a) Explain why this program has infinite recursion.

b) How would you correct this function to correctly calculate factorials?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!