Sunday, 12 December 2010

algorithm that use recursive function to find the factorial of a given integer

Algorithm: main program


Step 1: start
Step 2: read n
Step 3: call sub program as f=fact(n)
Step 4: print f value
Step 5: stop

Sub program:


Step 1: initialize the f
Step 2: if n= = 0 or n == 1 return 1 to main program if not goto step 3 Step 3: return n*fact(n-1) to main program

Output:


1. Enter the number : 5 Factorial of number: 120

2. Enter the number : 3 Factorial of number: 6

3. Enter the number : 9 Factorial of number: -30336

Conclusion: the program is error free




VIVA QUESTIONS:

1)  What is the meaning of factorial number?
  Ans : Factorial of a number is nothing but the multiplication of numbers from
            a given number to 1

2) What is the meaning of recusive function ?  
    Ans: A function call it self is called recursive function


3) Define library functions ?
  Ans: The functions have already been written, compiled and placed in libraries and are called library functions.

4)  Define formal parameters ?

  Ans: Formal parameters are the parameters given in the function declaration as function definition.


Algorithm


https://blog.penjee.com/wp-content/uploads/2015/04/top-5-programming-animated-gifs_recursion-animted-gif.gif

No comments:

Post a Comment