Factorial of a given number – C Program


Write a C program to find the factorial for a given number. [Dec 2014, Set-2]

#include <stdio.h>

int main()
{
    int i, n, fact = 1;
    
    printf("Enter a number :");
    scanf("%d", &n);

    for (i = 1; i <= n; i++)
    {
        fact *= i;
    }

    printf("The factorial of %d is %d.", n, fact);
    
    return 0;
}