## Description

Welcome to lapmos.com

Today we write a program of factorial program using function in c programming language.

So Now let's start the code..

```
#include<stdio.h>
int factorial(int n){
int fact = 1;
for(int i=1; i<=n; i++){
fact = fact * i;
}
return fact;
}
int main()
{
int n;
printf("Enter the number : ");
scanf("%d", &n);
int fact = factorial(n);
printf("The factorial of %d is %d", n, fact);
return 0;
}
```

**Output :**

Enter the number : 6

The factorial of 6 is 720

**Using recursive function **

```
#include<stdio.h>
int factorial(int n){
if(n==0){
return 1;
}
return n * factorial(n-1);
}
int main()
{
int n;
printf("Enter the number : ");
scanf("%d", &n);
int fact = factorial(n);
printf("The factorial of %d is %d", n, fact);
return 0;
}
```

**Output :**

Enter the number : 6

The factorial of 6 is 720

## Recommended Posts

## Prime number program in c | Calculate given number is prime or Not | prime number

What is prime number? and how to calculate the given number is prime or not |

## Largest Number | C programming language

Hello guys.. Today we write a program how to find the largest number ( greatest number ) in array c programming language.

## Swap two number without using third variable | C programming language

Write a program Swap two number withtout using third variable in c programming language.

## Fibonacci Series | Fibonacci Series in C | @lapmos

Fibonacci numbers ( sequence ) is a set of numbers that start with 1 or 0 followed by a 1 proceeds on the rule that each number.

## Palindrome | Palindrome program in c | Palindrome Number

Write a program in c to check that the given number is palindrome or not?