Friday, 17 October 2014

Find Factorial of a number using C programming

Find Factorial of a number using C programming
In mathematics, the factorial of a non-negative integer n, denoted by n! is the product of all positive integers less than or equal to n. For example,
    5! = 5 X 4 X 3 X 2 X 1 = 120.
Also factorial of 0! Is 1.
We are going to find out factorial by using C programming. Let’s see the code
#include<stdio.h>
#include<conio.h>
void main()
{
    int i,j,k=1;
    printf("Enter your number");
    scanf("%d",&i);
    for(j=1;j<=i;j++)
    {
        k=k*j;
    }
    printf("Factorial of number %d is %d",i,k);
}
In above program we use for loop to calculate the factorial. When we insert any value in this loop that value will be multiplied by all other integer value less than inserted value until loop ends.
Now let’s see the output
Enter your number 5
Factorial of number 5 is 120

1 comment: