Question: Recursive function program Write both an iterative and a recursive function to compute a factorial. Each should return an int. Your main program should print

Recursive function program

Write both an iterative and a recursive function to compute a factorial. Each should return an int.

Your main program should print a table with 3 columns. The first column is for an integer n (start with 1, increase n by 1 for each row), the second column is n! computed using recursion, the third column is n! computed using iteration. You decide how many rows to put in this table. Find the largest factorial you can correctly compute using the data type int. Be careful here. (Part of your grade is for you to identify this largest n.) Contemplate this carefully and even use the next version of this program to help you answer this question.

Even though the concept of a factorial is defined only for integers, change your data type for the factorial value in main and in both functions to double (8 bytes of storage as floating point) and find the largest factorial you can correctly estimate using this data type. Print the same table described above using your new functions. (Use these answers to help make your decision for the largest correct factorial value that can be saved as an int.)

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!