Thursday, 16 November 2017

C Program to Print the Factorial of a given Number


Code:

#include   stdio.h
void main()
{
    int i, fact = 1, num;

    printf("Enter the number \n");
    scanf("%d", &num);
    if (num <= 0)
        fact = 1;
    else
    {
        for (i = 1; i <= num; i++)
        {
            fact = fact * i;
        }
    }
    printf("Factorial of %d = %5d\n", num, fact);
}


Output:

Enter the number
10
Factorial of 10 = 3628800

More C Programs:












100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...