Factorial Program in C | Program in C to Calculate the Factorial of a Number

Posted in

Factorial Program in C | Program in C to Calculate the Factorial of a Number

Vinay Khatri
Last updated on August 28, 2022

    Here in this program, we will code to calculate the factorial of a number entered by the user. Read on Factorial Program in C.

    What is a Factorial?

    It is a mathematic concept mostly used in permutation, combination, and probability, its symbol is (!). In simple words, a factorial says multiply all whole numbers from our chosen number down to 1. For example, if we say 5 factorials in math it would be represented by 5! and evaluated by 5*4*3*2*1 = 120. By convention, the 0! is equal to 1.

    Use/Application of Factorial

    • In recursion we use Factorial
    • In permutation
    • In combination
    • In probability distribution

    C Statements we will use in the program:

    • For loop
    • * (multiplication arithmetic operator)

    Factorial Program in C

    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    long num, i,fact=1;
    clrscr();
    printf("Enter a number:");
    scanf("%ld",&num);
    for(i=num; i>=1; i--)
      { fact*=i;
      }
    printf("The factorial of the number %ld is %ld",num,fact);
     getch();
    }

    Output:

    Enter a number:10
    The factorial of the number 10 is 3628800

    People are also reading:

    Leave a Comment on this Post

    0 Comments