C program to find Factorial of a number

Factorial Number Using C

Mathematically, factorial of any number means to multiply a series of desecending natural numbers ie) upto 1.

Facts About Factorial Numbers

  • 5! is usually pronounced as "5 factorial" by mathematicians
  • Factorial of 0 is 1 i.e) 0! = 1

Pictorical View

Here is the most impressive structures built by humans in ancient time "The Pyramids".
C factorial number

C Program - Factorial Number

Let us write a c program to find factorial for user entered number
c-factorial-number.c
#include <stdio.h>
int main()
{
int a, i;
printf("Enter a number: ");
scanf("%d",&a);
for(i = a-1;i > 0;i--)
{
a *= i;
}
printf("%d ",a);
return 0;
}
Enter a number : 5
Factorial of 5 is 120

Note:

By closely looking at for-loop will give you a clear idea. Limit for a variable i is set from a-1 to 1 which is multiplied with the product of user entered number for every iteration.

Post a Comment

0 Comments