answersLogoWhite

0

First, the answer to what is factorial. Factorial is denoted by '!' N! = N * (N-1) * (N-2) * ... * 3 * 2 * 1. For example, 5! = 5 * 4 * 3 * 2 * 1 = 120.

There are two approaches to coding a function that will calculate n!. One does it iteratively, and the other recursively.

Iteratively:

factorial (n){

result <- 1

for(i <- 1; i <= n; i <- i + 1){

result <- result * i

}

return result

}

Recursively:

factorial (n){

if n is 1 return 1

return n * factorial(n - 1)

}

Note that n must be 1 or greater for each of the above methods.

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

Fatorial of a number program in javascript?

hi darling


What is the fatorial of 5?

5! = 5*4*3*2*1 = 120


How to write pseudocode in Microsoft Word?

To write pseudocode in Microsoft Word, you can use the built-in Equation Editor or insert a text box and type your pseudocode inside it. You can also use a monospaced font like Courier New to format your pseudocode for better readability.


Types of algorithm?

pseudocode


What is imitation code?

pseudocode


What is a pseudocode design tool?

SPOK (Structured Prose Organizer for KEDIT) is a pseudocode design tool. (SPOK4 at Verizon.Net)


Difference between pseudocode and structured English?

structured English resembles spoken Englishwhere as pseudocode resembles programming languageWhat_are_the_differences_between_structured_English_and_pseudo_code


Develop an algorithm to display all prime numbers from 2 to 100 Give both the pseudocode version and the flowchart version Convert your pseudocode into a Java program?

Develop an algorithm to display all prime numbers from 2 to 100. Give both the pseudocode version and the flowchart version. Convert your pseudocode into a Java program.


What is the difference between pseudocode and trace table?

pseudocode is a sentence-like representation of a piece of code while a trace table is a technique used to test a algorithms.


What is a text based approach to documenting an algorithm?

pseudocode


What are the importance of pseudocode?

enables the programmer to concentrate on algorithms.


Is a text based approach to documenting an algorithm?

pseudocode