C Example Factorial Number
What is factorial? Factorial of a number n (written as n!) is the product of all positive integers from 1 to n.
In Real world factorial using in multiple areas as follows
- Scheduling & Resource Allocation: Arranging tasks, machines, or workers in different possible orders.
- Cryptography: Large factorial numbers help in generating complex keys.
- Data Science / Machine Learning: Factorial-based combinations used in probability distributions (Binomial, Poisson).
- Gaming / Puzzle Design: Number of ways to shuffle cards (52! possible ways). Sudoku arrangement possibilities.
- Engineering / Reliability Analysis: Calculating probabilities of system failures (when multiple components work together).

Factorial Values Example:
n! = n 0 = 1 1 = 1 2 = 2 3 = 6 4 = 24 5 = 120 6 = 720 7 = 5.040 8 = 40.320 9 = 362.880 10 = 3.628.800 11 = 39.916.800 12 = 479.001.600
C Program to Find Factorial of a Number
Example Code 1:
- C code for factorial of a number
- C program to find the factorial of a given number
- Factorial program in c using while loop
- โฏFactorial program in c without using recursion
#include<stdio.h>
int main()
{
โฏ int i=1,f=1,num;
printf("C Example Factorial Number");
โฏ printf("Enter a number: ");
โฏ scanf("%d",&num);
โฏ while(i<=num)
{
โฏโฏโฏโฏโฏ f=f*i;
โฏโฏโฏโฏโฏ i++;
โฏ }
โฏ printf("Factorial of %d is: %d",num,f);
โฏ return 0;
}
/*
Sample output:
Enter a number: 5
Factorial of 5 is: 120
*/
Explanation:
f=f*i;โ multiplies the current result withieach time.while(i<=num)ensures multiplication continues until all numbers from 1 tonumare covered.fstarts with 1 because multiplying by 0 would always give 0.- If you enter
0, the loop wonโt run, sofremains1โ which matches the definition0! = 1.
Code 2:
- Factorial program in c using for loop
- Simple factorial program in c
- C program to calculate factorial
#include<stdio.h>
int main()
{
โฏ int i,f=1,num;
โฏ printf("Enter a number: ");
โฏ scanf("%d",&num);
โฏ for(i=1;i<=num;i++)
โฏโฏโฏโฏโฏ f=f*i;
โฏ printf("Factorial of %d is: %d",num,f);
โฏ return 0;
}
Example Code 3:
- Factorial program in c using pointers
- How to calculate factorial in c
- Factorial program in c language
#include<stdio.h>
void findFactorial(int,int *);
int main()
{
โฏ int i,factorial,num;
printf("Enter a number: ");
โฏ scanf("%d",&num);
โฏ findFactorial(num,&factorial);
โฏ printf("Factorial of %d is: %d",num,*factorial);
โฏ return 0;
}
void findFactorial(int num,int *factorial)
{
โฏโฏโฏ int i;
โฏโฏโฏ *factorial =1;
โฏโฏโฏ for(i=1;i<=num;i++)
โฏโฏโฏโฏโฏ *factorial=*factorial*i;
}
Code 4:
- Factorial program in c using function
- C program to find factorial of a number
#include<stdio.h>
int findFactorial(int);
int main()
{
โฏ int i,factorial,num;
printf("Enter a number: ");
โฏ scanf("%d",&num);
โฏ factorial = findFactorial(num);
โฏ printf("Factorial of %d is: %d",num,factorial);
โฏ return 0;
}
int findFactorial(int num)
{
โฏโฏ int i,f=1;
โฏโฏโฏ for(i=1;i<=num;i++)
โฏโฏโฏโฏโฏ f=f*i;
โฏโฏโฏ โฏreturn f;
}
/*
Sample output:
Enter a number: 8
Factorial of 8 is: 40320
*/
Code 5: Factorial series in c
#include<stdio.h>
int main()
{
โฏ long f=1;
โฏ int i,num,min,max;
โฏ printf("Enter the minimum range: ");
โฏ scanf("%d",&min);
โฏ printf("Enter the maximum range: ");
โฏ scanf("%d",&max);
โฏ printf("Factorial series in given range: ");
โฏ for(num=min;num<=max;num++){
โฏโฏโฏ f=1;
โฏโฏโฏ for(i=1;i<=num;i++)
โฏโฏโฏโฏโฏ f=f*i;
โฏโฏโฏ printf("%ld ",f);
โฏ }
โฏ return 0;
}
/*
Sample output:
Enter the minimum range: 1
Enter the maximum range: 10
Factorial series in given range: 1 2 6 24 120 720 5040 40320 362880 3628800
*/
Previous & Next
- Previous : C Examples Number System Conversion
- Next : C Example Perfect Number