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.

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);

`}`

advertisements

$ 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

If you wish to look at other example programs on Mathematical Functions, go to C Programming Examples on Mathematical Functions. If you wish to look at programming examples on all topics, go to C Programming Examples.