Wednesday , January 17 2018
most suggested
Home / c-program / C Program – Find the factorial of given number

# C Program – Find the factorial of given number

C Program to find the factorial of given number.

## Factorial Of Given Number :

```
#include<stdio.h>
int main(void)
{
int n,num;
long fact=1;
printf("Enter any number : ");
scanf("%d",&n);
num=n;
if(n<0)
printf("Invalid Number(-ve)\n");
else
{
while(n>1)
{
fact*=n;
n--;
}
printf("Factorial of %d is : %ld\n",num,fact);
}
return 0;
}

```

Enter any number : 10
Factorial of 10 is : 3628800

Enter any number : -5
Invalid Number(-ve)

## Factorial Of Given Number Recursive:

```
#include<stdio.h>
long int factorial(int n);
int main(void)
{
int num;
printf("Enter any number : ");
scanf("%d", &num);
if(num<0)
printf("Invalid Number(-ve)\n");
else
printf("Factorial of %d is : %ld\n", num, factorial(num) );

return 0;
}

long int factorial(int n)
{
if(n==0)
return 1;
return(n*factorial(n-1));
}
```

Enter any number : 5
Factorial of 5 is : 120

Enter any number : -5
Invalid Number(-ve)

Happy Learning 🙂

Hi
Folks,
you have reach this so far, that shows you like what you are learning. Then why don’t you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

## C Program – Addition of two Matrices Example

C Program to Addition of two Matrices. Addition of two Matrices : Happy Learning 🙂