C Programming
- Print integer
- Add & subtract
- Odd & even
- Multiply & divide
- Check vowels
- Letter grade program
- Leap year program
- Sum of digits
- Prime numbers
- Sum of numbers
- Find factorial
- Fibonacci series
- Fibonacci triangle
- Number triangle
- Alphabet triangle
- Armstrong numbers
- Palindrome numbers
- Swap number
- Reverse number
- Decimal to binary
- Assembly code in C
- Matrix multiplication
- HCF & LCM
- nCr & nPr
- Print pattern
- Floyd’s triangle
- Pascal triangle
- Count digits
- Strong numbers
- Perfect numbers
- Sum of natural number
- Binary to decimal
- Decimal to octal
- Octal to decimal
- Binary to octal
- Octal to binary
- Add using pointer
- Bubble sort
- Insertion sort
- Selection sort
- Quick sort
- Binary search
- Linear search
- Largest element of array
- Smallest element of array
- Reverse Array
- Variable size & limit
- ASCII value of character
- Sum of array elements
- Number of element in array
- Merge two array
- Insert element in array
- Delete element from array
- Add two matrix
- Transpose matrix
- Print string
- Reverse string
- Delete vowels
- Sort string
- Remove spaces
- Swap string
- Random numbers
- Print date & time
- Print IP address
- Shut down computer
Find factorial of an integer
Factorial of an integer n is denoted by n! and determined as the product of all the positive descending integers. Factorial of an integer n is determined by the following equation;
n! = n * (n – 1) * (n – 2) * (n -3) * ……. * 3 * 2 * 1
If you want to determine the factorial of an integer 6, then the result will be as the following;
6! = (6 * 5 * 4 * 3 * 2 * 1) = 720
It should be mentioned that 0! = 1.
In this article we will try to understand and write factorial program in C programming language. We can write a factorial program in different methods. So of the methods of writing factorial program in C are as follows;
- Factorial program using loop in C
- Factorial program using function or recursion in C
Now, let’s see some C programs to find out factorial of an integer in C.
Factorial program using loop in C
// factorial program using loop in c
#include <stdio.h>
int main(){
int number, i, fact = 1;
printf("Enter the number for calculating its factorial : ");
scanf("%d", &number);
for (i = 1; i <= number; i++){ // using loop to calculate factorial
fact = fact * i;
}
printf("\nFactorial of %d is = %d\n", number, fact);
return 0;
}
Output of this factorial program:

Factorial program using function in C
// factorial program using function or recursion in c
#include<stdio.h>
long fact(int num){ // function to calculate factorial
if (num == 0){
return 1;
}else{
return (num * fact(num - 1));
}
}
int main(){
int num;
long factorial;
printf("Enter the integer to find factorial : ");
scanf("%d", &num);
if (num < 0){
printf("Factorial of negative integer is undefined.\n");
}else{
factorial = fact(num);
printf("%d! = %ld\n", num, factorial);
}
return 0;
}
Output of this C factorial program

Previous page: Sum of natural numbers
Next page: Fibonacci series