Access over 35 million academic & study documents

3 Given the following recursive function int myFactorial (int in

Content type
User Generated
Showing Page:
1/2
3. Given the following recursive function:
int myFactorial (int integer)
{
if (integer == 1)
{
return 1;
}
else
{
return (integer * (myFactorial (integer 1));
}
}
Show all the calls to the function and what each one
returns to its predecessor.
int result = myFactorial (5);
Solution
when
int result = myFactorial(5);
is executed \"myFactorial\" is called with input 5
As 5 is not equal to 1
myFactorial(5) returns
5*myFactorial(5-1)
=5*myFactorial(4)
result=5*myFactorial(4)

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/2

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
3. Given the following recursive function: int myFactorial (int integer) { if (integer == 1) { return 1; } else { return (integer * (myFactorial (integer – 1)); } } Show all the calls to the function and what each one returns to its predecessor. int result = myFactorial (5); Solution when int result = myFactorial(5); is executed \"myFactorial\" is called with input 5 As 5 is not equal to 1 myFactorial(5) returns 5*myFactorial(5-1) =5*myFactorial(4) result=5*myFactorial(4) As 4 is not equal to 1 myFactorial(4) returns 4*myFactorial(4-1) =4*myFactorial(3) result=5*4*myFactorial(3) As 3 is ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4