Saturday, September 20, 2008

C program for Factorial of a given number using recursive function

#include "stdio.h"

/*
The following code gives factorial of any give integer
*/
unsigned int factorial(int num)
{
    if(num == 1 || num == 0)
       return 1;
    else
       num = num * factorial(num - 1);
}

void main()
{
   int y = 5;

  /*
   Check if the user gives a negative number
  */
   if(y < 0)
       printf("Factorial of negative numbers doesnot exist");
    else
   /*
    Call the function
   */
    printf(" Factorial of %d is %u", factorial(y));

    return;
}

1 comment:

Unknown said...

Nice post but do you know how to find factorial of large numbers