FACTORIAL OF A NUMBER USING RECURSION
Do you like this story?
Write a program to calculate the factorial of a number. Use the concept of recursion
instead of using loops.
#include<stdio.h>
void main()
{
int a, fact;
printf("\nEnter any number: ");
scanf ("%d", &a);
fact=rec (a);
printf("\nFactorial Value = %d", fact);
}
rec (int x)
{
int f;
if (x==1)
return (1);
else
f=x*rec(x-1);
return (f);
}
Output:
Enter any number:3Factorial Value = 6

This post was written by: Rajendra Prasad
Rajendra Prasad is a professional blogger, web designer and front end web developer. Follow him on Facebook