Write a simple recursive function to calculate a factorial I

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)!

Solution

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

 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). Wri

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site