Pages

Monday, December 31, 2018

C-Program to Find Factorial of a Number

 C Program to Find Factorial of Any Given Number


Following is the Program: You can simply copy it to make your program.
____________________________________________________________________________________

#include<stdio.h>
#include<conio.h>
int main()
{
    int n,i,fact;

    printf("Enter a Number:");
    scanf("%d",&n);
   
    fact=n;
   
    if(n==0)
    {
        fact=1;
    }
    else
    {
        for(i=n-1 ; i>=1 ; i--)
        {
        fact=fact*i;
        }
    }
    printf("Factorial of %d is %d",n,fact);
   
    getch();
    return 0;   
}

____________________________________________________________________________________
Output:

For example I have entered a no. as 5 and it gives me an output as 120.
It means the Factorial of 5 is 120.


Hope you like our program. For more Please Comment.

No comments:

Post a Comment