This is a C Program to print the factorial of a given number.

This C Program prints 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.

Here is source code of the C program to print the factorial of a given number. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/* * C program to find the factorial of a given number */ #include <stdio.h> void main() { int i, fact = 1, num; printf("Enter the number \n"); scanf("%d", &num); if (num <= 0) fact = 1; else { for (i = 1; i <= num; i++) { fact = fact * i; } } printf("Factorial of %d = %5d\n", num, fact); }

In this C program, we are reading the integer number using ‘num’ integer variable. A factorial is a product of all the numbers from 1 to n, where n is the user specified number.

If condition statement is used to check the value of ‘num’ variable is less than or equal to 0. If the condition is true then it will execute the statement and assign the value of ‘fact’ variable as one. Otherwise, if the condition is false then it will execute the else statement. Using for loop multiply all the numbers from 1 to n and display the factorial of a given number as output.

$ cc pgm79.c $ a.out Enter the number 10 Factorial of 10 = 3628800

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms