Friday 26 November 2010

write a recursive function for n

write a recursive function for n

long double fact(int n)
{
 if(n>0)
  return(n*fact(n-1));
 else
  return(1);
}
main()
{
 int n;
 long double fact(int);
 printf("enter any +ve integer (or) 0\n");
 scanf("%d",&n);
 printf("%d!=%Lf\n",n,fact(n));
 getch();
}

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.



No comments:

Post a Comment