Factorial of a Number program in C

In this, we learn about factorial program in c language. Here I cover topics like what is factorial, factorial formula, c program to calculate factorial of a number and example of factorial design.

Factorial program in c?

Factorial of a number is a product of given integer number from a given integer to till 1 with it's all integers less than or equal to the given number but greater than or equal to 1. Factorial is denoted by an exclamation mark (!). Factorial values for negative integers are not defined. Factorial value of 0 is defined as equal to 1.
we can write 0 factorial as 0!  or n factorial as n! 
where n is an integer number. 

factorial of a number


Factorial Formula

factorial formula to calculate factorial n = n * (n-1) * (n-2) * (n-3) * ... * 3 * 2 * 1
where n is given integer number
For example, 
find 5 factorial 
5! = 5 * 4 * 3 * 2 * 1 = 120.

Example of calculate factorial 

6 factorial,   6! = 720
9 factorial, 9! = 362880
20 factorial, 20! = 2432902008176640000
25 factorial, 25! = 1.551121004×1025
50 factorial, 50! = 3.041409320×1064

Factorial program in C


#include<stdio.h>
int main()
{             
   int n,fact=1,i;
 printf("\n Enter the number:");
 scanf ("%d",&n);
   for(i=1;i<=n;i++)
   {
    fact=fact*i;
   }
   printf("Factorial of %d is %d",n,fact);
          return 0;
}

Output

Enter the number:
3
Factorial of 3 is 6

Above we ask the user for a number and output will appear and also learn about factorial, factorial formula, examples in which we also cover factorial program in c using for loop with output. If you have any doubts about c program or in any other do not hesitate and comment below.

Share this

Tag :

0 Comment to "Factorial of a Number program in C"

Post a Comment