Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ECIV 201 Classroom Exercise # 06 (10 points) Work in pairs (or individually if y

ID: 3752913 • Letter: E

Question

ECIV 201 Classroom Exercise # 06 (10 points) Work in pairs (or individually if you wish) Creating functions in Excel (continued) Adapted from Problem 2.25 of the text. The pseudocode in Fig. P2.25 computes the factorial. Create an Excel function follows this algorithm. Test it by computing O! and 51 In addition, test the error trap by trying to evaluate -2 FUNCTION fac(n) Fn20 THEN DOFOR 11, n END DO fac= x ELSE display error message terminate ENDIF END fac FIGURE P2.25 Grading will be based on the following: 8 points-correctness of the function calculations. 2 points- ability to catch and flag errors. This will tested using negative values of n.

Explanation / Answer

The Excel fact function returns a factorial of a supplied number.

Syntax is : FACT(number) where the number argument is a positive integer which we have to calculated

FACT(n) // here n is the number

If n>=0 then

x=1

Do for i =1,n

x=x * i

END D0

FACT=x

ELSE

display error message

terminate

ENDif

END FACT

For example if we take the number as 0 then it computes factorial as 0!=1

If we take the number as 5 then it computes 5!=5*4*3*2*1=120

If we take the number as negative i.e -2! It gives the error from the NUM! that is the number is supplied as <0