Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a simple recursive function to calculate a factorial. In math the symbol!

ID: 3936273 • Letter: W

Question

Write a simple recursive function to calculate a factorial. In math the symbol! is used for the factorial (don't confuse it with the java symbol for not). Write a main program that allows the user to enter test values and sec the results. Read about recursion in the text, Chapter 11.1. Write pseudo code as usual. You must write a recursive function, not use the closed formula. Recursive functions call themselves. A factorial of any integer greater or equal to 0 is defined as follows: 0! is always 1 1! is 1 2! is 2 * 1 or 2 3! is 3 * 2 * 1 or 6 4! is 4 * 3 * 2 * 1 or 24 To make this calculation in general use recursion: n! is n * (n-1)!

Explanation / Answer

Solution:

/* FactorialDemo.java

*/

Output:

Enter the number: 5 Factorial of entered number is: 120

Pseudocode:

fact=1
n=input(“Please, Enter a number ”)
c=1
while(c<=n):
fact=fact*c
c=c+1
print “The factorial of “, n , “ is “, fact

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote