Question #76171

Write a pseudocode version of the factorial function . . .

(a) iteratively.

(b) recursively.
1

Expert's answer

2018-04-19T08:16:15-0400

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 n2 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/)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS