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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started