In this tutorial, We learn about the factorial program in c. Here I cover topics like what is factorial, formula, and C program.
Factorial in C
Factorial 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. It is denoted by an exclamation mark (!). It values for negative integers are not defined. Factorial value of 0 is defined as equal to 1.
Formula
Factorial of a number = n * (n-1) * (n-2) * (n-3) * ... * 3 * 2 * 1
where n is given integer number
For example,
5! = 5 * 4 * 3 * 2 * 1 = 120.
Factorial Example
6! = 720
9! = 362880
20! = 2432902008176640000
25! = 1.551121004×1025
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
In this article, we learn c program to find factorial of a number. If you have any doubts about do not hesitate and comment below.
Happy Coding 😊
Tags:
C