Write a C program for calculating the factorial of a number

Here is a recursive C program

fact(int n)
{
     int fact;
     if(n==1)
         return(1);
     else
         fact = n * fact(n-1);
     return(fact);
}

Please note that there is no error handling added to this function (to check if n is negative or 0. Or if n is too large for the system to handle). 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Post Navigation