Thursday, January 19, 2012

C Program to calculate factorial of a number

Iterative:
int findFactorial(int num){
    int i,f=1;

    for(i=1;i<=num;i++)
      f=f*i;

     return f;
}
Recursive:

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

No comments:

Post a Comment