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.
hi darling
5! = 5*4*3*2*1 = 120
pseudocode
pseudocode
SPOK (Structured Prose Organizer for KEDIT) is a pseudocode design tool. (SPOK4 at Verizon.Net)
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.
pseudocode is a sentence-like representation of a piece of code while a trace table is a technique used to test a algorithms.
There is no standard for pseudocode. Pseudocode is generally expected to be intuitively understood by its target audience, but it doesn't need similarity with natural language or familiar programming language. Therefore, all the following are pseudocode examples to increment a variable called rep: rep = rep + 1 add 1 to rep increment rep ++rep next rep
pseudocode
enables the programmer to concentrate on algorithms.
pseudocode