Breaking News

C Program to Find Factorial of a Number

Example: Factorial of a Number

#include <stdio.h>
int main()
{
    int n, i;
    unsigned long long factorial = 1;

    printf("Enter an integer: ");
    scanf("%d",&n);

    // show error if the user enters a negative integer
    if (n < 0)
        printf("Error! Factorial of a negative number doesn't exist.");

    else
    {
        for(i=1; i<=n; ++i)
        {
            factorial *= i;              // factorial = factorial*i;
        }
        printf("Factorial of %d = %llu", n, factorial);
    }

    return 0;
}

Output

Enter an integer: 10
Factorial of 10 = 3628800

3 comments

  1. C program to find factorial of an integer entered by user with example and explanation.

  2. C program to find factorial of an integer entered by user with example and explanation.

Leave a Reply

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

*

Scroll To Top