program to calculate the factorial of the number by recursion in c-language.
In this program, we will learn to find the factorial of the natural number by using recursion and user entered the value.
we will use a recursive user defined function to perform the task .
The factorial of a negative number doesn't exit .
The factorial of 0 is 1.
recursion mean function calling itself .
#include<stdio.h>
#include<conio.h>
int factorial(int num);
void main()
{
int n,f=0;
printf("enter the number");
scanf("%d",&n);
f=factorial(n);
printf("the factorial of the number is %d",f);
getch();
}
int factorial(int num)
{
if(num>0)
return(num*factorial(num-1));
else
return(1);
}
output
enter the number : 5
factorial of 5 is 120
For more c-programming example:
1.c-program to calculate the GCD of two number by recusion
2.c-program to display fibonacci series by using recusion
3.c-program to calculate the sum of the number by using recursion
No comments:
Post a Comment