Factorial Program in C | C program for Factorial of a Number
Introduction Factorial:
In this article, We are going to discuss about the Factorial Program in C Language.
Factorial of a Number:
In mathematics, the factorial of a non-negative integer n, denoted by
n!
The Factorial is the product of all positive integers less than or equal to n.
For example, Factorial of 5 is
- 5! = 5*4*3*2*1 i.e 120
The value of 0! is 1, according to the convention for an empty product.
Factorial Program in C Language :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include<stdio.h> main() { int n,fact=1,i; Label: printf("Enter a Number :"); scanf("%d",&n); if(n<0) { printf("No Factorial for Negative Non"); goto Label; } else { if(n == 0) fact = 1; else { for(i=1;i<=n;i++) fact =fact*i; } } printf("Factorial of %d is : %d\n",n,fact); } |