Answer to Question #76171, Programming & Computer Science / Algorithms
Write a pseudocode version of the factorial function
(a) iteratively
Answer:
Input: n // first n positive integers
If n ≤ 2 then
Fact = n;
Else {
Fact = 2
For i = 3 to n
Fact = Fact * i
}
Return Fact // n!(b) recursively
Answer:
Function Fact(n) {
If n ≤ 2 then
Return n;
Else
Return n * Fact(n - 1)
}Print to PDF without this message by purchasing novaPDF (http://www.novapdf.com/)
Comments