C Programming Code Examples C > Mathematics Code Examples Program to Print the Factorial of a given Number Program to Print the Factorial of a given Number This C Program print the factorial of a given number. A factorial is product of all the numbers from 1 to n, where n is the user specified number. This program find the product of all the number from 1 to the user specified number. #include <stdio.h> void main() { int j, fact = 1, x; printf("Enter the number \n"); scanf("%d", &x); if (x <= 0) fact = 1; else { for (j = 1; j <= x; j++) { fact = fact * j; } } printf("Factorial of %d = %5d\n", x, fact); }