Factorial Program in C Using Recursion

Factorial program in c using recursion for beginners to understand the recursion concept. In this program, we can execute the factorial program in recursion.

Factorial Definition in C

The product of all positive descending integers is the factorial of n.

n! denotes the factorial of n. the sum of all positive integers that are less than or equal to a given positive integer, denoted by that integer and an exclamation point

Long Int Data Type in C

On the same machine, a long integer can represent a whole integer with a range that is greater than or equal to that of a standard integer.

It is denoted by long in C. It must be at least 32 bits long and may or may not exceed the size of a standard integer.

Function Definition in C

A function is a collection of statements that work together to complete a task.

Every C program has at least one function, main(), and even the simplest programs can define more functions.

The name, return type, and parameters of a function are all specified in a function declaration.

#include<stdio.h>
long int func(int n);
int main()
{
int n;
printf("Enter The Positive Number ");
scanf("%d",&n);
printf("Factorial of %d = %ld", n, func(n));
return 0;
}
long int func(int n)
{
if (n>=1)
return n*func(n-1);
else
return 1;
}

Output:

Enter The Positive Number 5
Factorial of 5 = 120