The pseudocode in Fig computes the factorial Express this al

The pseudocode in Fig. computes the factorial. Express this algorithm as a well-structured function in the language of your choice. Test it by computing 0! and 5!. In addition, test the error trap by trying to evaluate -2!. In VBA code.

FUNCTION fac(n) IF n 2 0 THEN DOFOR 1, n END DO fac ELSE display error message terminate ENDIF END fac

Solution


Function fac(n)
if n > 0 then

  fact = 1
  OrgNo = n
  i = 1
  Do While n >= i
     fact = fact * i
     i = i + 1
  Loop
  
  msgbox \"The Factorial of n is : \" & fact
  
else
      msgbox \"Error! Factorial of a negative number does notexist\"
end if  

End Function

The pseudocode in Fig. computes the factorial. Express this algorithm as a well-structured function in the language of your choice. Test it by computing 0! and

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site