C Program to Find Factorial of a Number

Program : -


#include<stdio.h>
#include<conio.h>
int main()
{
    int n, count;
    unsigned long long int factorial=1;         
    printf("Enter an integer: ");
    scanf("%d",&n);
    if ( n< 0)
        printf("Error!!! Factorial of negative number doesn't exist.");
    else
    {
       for(count=1;count<=n;++count)    /* for loop terminates if count>n */
       {
          factorial*=count;              /* factorial=factorial*count */
       }
    printf("Factorial = %lu",factorial);
    }
    getch();
}




Output 1 : -

Enter an integer: -5
Error!!! Factorial of negative number doesn't exist.

Output 2 : -

Enter an integer: 10
Factorial = 3628800