Factorial of a number (n!):How to Print a FACTORIAL in c program first you have to know what is a FACTORIAL? To Print a FACTORIAL you have to clear your logic.Lets begin,
What is factorial of a number?

Factorial is denoted by the symbol ‘!’. For example, factorial of a number 10 is denoted as 10!. Factorial of a number is defined as the product of “the number and all integers less than that number except zero and negative integers”.

Natural numbers ( nonnegative integers ) which are greater than zero are used for factorial concept.
Factorial Example:
Zero factorial (0!) = 1
one factorial (1!) = 1
Two factorial (2!) = 2*1 = 2
Three factorial (3!) = 3*2*1 = 6
Four factorial (4!) = 4*3*2*1 = 24
Five factorial (5!) = 5*4*3*2*1 = 120
etc…
The common mathematical formula for finding factorial of the number ‘n’ is given below.
n! = n ( n – 1)( n – 2)( n – 3) …… (1)
C Program to Print FACTORIAL:
#include <stdio.h> int main() { int i,fact=1,n; printf("\nPlease enter a number to find factorial : "); scanf("%d",&n); if (n<0) { printf("\nPlease enter a positive number to find factorial and try again.Factorial can't be found for negative values. It can be only positive or 0 \n"); return 1; } for(i=1;i<=n;i++) fact=fact*i; printf("Entered number is %d and it's factorial is %d! = %d\n",n,n,fact); return 0; }
OUTPUT:
Please enter a number to find factorial :5
Entered number is 5 and it’s factorial is 5! = 120 
Leave a Reply