# 19+ C Factorial Calculator Examples

This post contains a total of 19+ Hand-Picked C Factorial Calculator Examples with Source Code. All the Factorial Calculators are made using C Programming language.

You can use the source code of these programs for educational purpose with credits to the original owner.

### Related Posts

Click a Code to Copy it.

## 1. By Mechatronic

Made by Mechatronic. C Program to find the factorial of a number without using loops. It is only possible to the number 12, higher numbers need higher memory space. ( Source )

``````#include <stdio.h>
#include <stdlib.h>

int fac(int a)
{
if(a<1)
{
return 1;
}
else
{
return a*fac(a-1);
}
}
int main()
{
int faktor;

printf ("Please insert the factorial number:\n");
scanf("%d", &faktor);

printf ("The result is:%d", fac(faktor));

return 0;
}``````

## 2. By Hamid Sarkarwale

Made by Hamid Sarkarwale. Simple program to calculate the factorial of any number. ( Source )

``````
#include <stdio.h>
int main()
{
int num,i,factorial=1;
printf("Enter the number: ");
scanf("%d",&num);
if(num<0)
{
printf("error! factorial doesn't exist.");
}
else if(num==0 || num==1)
{
printf("factorial=%d",factorial);
}
else
{
for(i=num;i>=1;i--)
{
factorial=factorial*i;
}
printf("factorial=%d",factorial);
}
return 0;
}``````

## 3. By Shail Murtaza

Made by Shail Murtaza. Enter your number in line ‘  n = 20; ‘. ( Source )

``````#include <stdio.h>

int main() {
int i = 1, n;
n = 20;
unsigned long long int f = 1;
while (i<=n) {
f *= i;
i++;
}
printf("%llu", f);
return 0;
}``````

## 4. By Γmer Tozkoparan

Made by Γmer Tozkoparan. ( Source )

``````#include <stdio.h>
int main() {

int a,f=1;
scanf("%d", &a);
for(int i=1;i<=a;i++){
f=f*i;
}
printf("%d", f);
return 0;
}``````

## 5. By Kevin

Made by Kevin. Factorial calculator (integer limit = !12) example : 4, !4 = 24. ( Source )

``````#include <stdio.h>

int main() {
int i, n, result = 1;

scanf("%d", &n);

for (i = 1; i <= n;i++) {
result = result * i;
}

printf("!%d = %d", n, result);
return 0;
}``````

## 6. By Borhan Petgar

Made by Borhan Petgar. ( Source )

``````#include <stdio.h>
int main()
{
long int fact , num , i;
for(;;)
{
printf("\ntype a number :");
scanf("%d",&num);
fact = 1;
for (size_t i = 1; i <= num; i++)
fact *= i ;
printf("Factorial is %ld", fact);
break;
}
return 0;
}
``````

## 7. By Basil Uche

Made by Basil Uche. Simple arithmetic calculator that also run factorial of numbers, first input for arithmetic calculation then input a number to get its factorial. ( Source )

``````
int factorial(int num)
//function definition
{

if (num== 1)
return (1);
else
return (num * factorial(num - 1));
}

#include <stdio.h>
int main() {
float  a1,a2,score;
char opr;
scanf("%f",&a1);
scanf ("%c",&opr);
scanf ("%f",&a2);

switch (opr )
{
case '+':
score=a1+a2;

break ;

case '-':
score=a1-a2;
printf ("the subtraction is=%.1f\n",score);
break ;

case '*':
score=a1*a2;
printf ("the multiplication is=%.1f\n",score);

break ;

case '/':
score=a1/a2;
printf("the division is =%.1f\n",score);

break ;

default :
printf ("enter all options!\n");}

int x ;
scanf("%d",&x);
printf("The factorial of %d is %d\n", x, factorial(x));

printf ("\nthanks for runnig the code hope you like(+1) it");
return 0;

}

``````

## 8. By Babak Barzegar

Made by Babak Barzegar. ( Source )

``````#include <stdio.h>
int factorial(int x){
int product;
product =1;
for (x;x>1;x=x-1)
product = product *x;
return(product);
}
main() {
int a;
scanf("%d",&a);
a = factorial(a);
printf ("%d",a);
}``````

## 9. By Siphosethu Nkutu

Made by Siphosethu Nkutu. ( Source )

``````#include <stdio.h>

int fact (int y);

int main() {
int  y, result;

printf ("enter a number you will get its factorial\n");
scanf("%d",&y);
result = fact(y);
printf(" the factorial of %d is %d\n",  y, result);

return 0;
}

int fact (int y) {
if(y <=1)
return(y);
else {
return y * fact (y - 1);
}
} ``````

## 10. By Jean Marie Uwimana

Made by Jean Marie Uwimana. ( Source )

``````#include <stdio.h>
#include <locale.h>

int main() {
int n;
scanf("%d", &n);
int p = FactorialCalculation(n);
setlocale(LC_ALL,"");
printf("%'d\n", p);
}
int FactorialCalculation(n){
if(n == 0)
return 1;
else return n*FactorialCalculation(n-1);
}
``````

## 11. By attackhelicopter boi

Made by attackhelicopter boi. C Factorial calculator made using pointers. ( Source )

``````#include <stdio.h>
#include <stdlib.h>
void fac(int* ptr);
int main() {
int* z = (int*) malloc(sizeof(int));
if (z == NULL) {
printf("Memory not allocated");
exit(0);
}
printf("Enter n.\n");
scanf("%d", z);
fac(z);
free(z);
return 0;
}
void fac(int* ptr) {
if (*ptr >= 0) {
if(*ptr == 0 || *ptr == 1) printf("1");
else {
int d = 1;
for (int i = *ptr; i > 0; i--) d *= i;
printf("%d! = %d", *ptr, d);
}
} else {
printf("Enter a valid number.");
}
}
``````

## 12. By Tyler Nagle

Made by Tyler Nagle. When given a value, this program will calculate the factorial, which is the product of every natural number up to the number entered. For instance, 3! = 321. ( Source )

``````#include <stdio.h>
#include <math.h>

int main() {

int con, num, fact = 1;

scanf("%d", &num);

for(con = 1; con<=num; con++)
{
fact *= con;
}

printf("%d! is equal to %d", num, fact);

return 0;
}``````

## 13. By Ndambia brian

Made by Ndambia brian. ( Source )

``````#include<stdio.h>
int main()
{
int factorial (int);

int n;
printf("This program find n!\nEnter n:  ");
scanf("%d",&n);
printf("\n %d! is %d",n,factorial(n));

}
int factorial (int m){
int y = 1;
for(int h = 2; h <= m; h++){
y = y * h;

}
return y;
}``````

## 14. By Harshit Paliwal

Made by Harshit Paliwal. ( Source )

``````#include <stdio.h>

int main()
{
int x,f=1;
printf("Enter the number whose factorial you want to obtain:");
scanf("%d",&x);
printf("%d",x);
for(int i=1;i<=x;i++)
{
f=f*i;
}
printf("\nThe factorial of %d is : %d",x,f);
return 0;
}``````

## 15. By Nafis Mahmud

Made by Nafis Mahmud. ( Source )

``````#include <stdio.h>

int main() {
int a,b=1,i;
scanf("%d",&a);
for(i=a;i>0;i=i-1) {
b=b*i;
}
printf("The factorial of the number is %d",b);
return 0;
}``````

## 16. By prathmesh chaudhari

Made by prathmesh chaudhari. This program calculates factorial of given int type number. ( Source )

``````#include <stdio.h>

int calcfac (int n){

int  i, result = 1;

printf ("This is n %d\n \n", n );

if ( n < 0)
printf (" Oops! This program does'nt calculate factorial of NEGATIVE integer Please try positive one!!\n");

for ( i=1 ; i <= n ; i++){

printf ("%d * %d = ", result , i);
result = result * i;
printf ("%d\n", result);
}

return result ;
}

int main() {

int num ;

scanf ("%d", &num);

printf ("\nFactorial of %d is %d",num ,calcfac (num) );
return 0;
}``````

## 17. By Bhagyesh Patil

Made by Bhagyesh Patil. ( Source )

``````#include<stdio.h>

int main()
{
int num,fact=1;
int i=1;
printf("Enter the number to Find Factorial :-\n");
scanf("%d",&num);
while(i<=num)
{
//printf("%d\n",i); only for the value of the i
fact =fact*i;
i++;
}
printf("Factorial is %d!= %d",num,fact);
return 0;
}``````

## 18. By Ayberk Gerey

Made by Ayberk Gerey. Simple factorial finder with a function.( Source )

``````#include <stdio.h>

int fact(int n)
{
if(n==0){return 1;}
else{return n*fact(n-1);}
}

int main()
{
int n;
printf("\nEnter a value that you want it's fact =  ");
scanf("%d",&n);
printf("\n\n%d",fact(n));

return 0;
}``````

## 19. By Rishi Raj Gautam

Made by Rishi Raj Gautam.. ( Source )

``````#include <stdio.h>
int main()
{
int i,m,n=1;
printf("Number for the factorial: ");
scanf("%d",&m);
for(i=1;i<=m;i++)
{
n=i*n;
}
printf("Factorial of %d is %d",m,n);
}``````

## 20. By Akash

Made by Akash. ( Source )

``````#include<stdio.h>

int main()
{
int num;
scanf("%d",&num);
int result = 1;
int i;

for (i=1;i<=num;i+=1)
{
result *= i;
}
printf("%d", result);
return 0;
}``````