C Program to find Factorial using recursion
Program
#include
<stdio.h>
#include<conio.h>
long int
factorial(int n)
{
if(n==1)
return 1;
return
n*factorial(n-1);
}
int main()
{
int num;
long int
fact=0;
printf("Enter
an integer number: ");
scanf("%d",&num);
fact=factorial(num);
printf("Factorial
of %d is = %ld",num,fact);
printf("\n");
return 0;
}
Output:-
Enter an integer number: 5
Factorial of 5 is = 120
No comments:
Post a Comment