February 14, 2011

C Program for Factorial of a Number using Recursive Function


This code is shared by Shweta Jhunjhunwala, thanks for your contribution.
Share your C, C++,C# program with us we will post them here..

Code:
/*C Program for Factorial of a Number using Recursive Function */
#include<stdio.h>
#include<conio.h>
long int factorial(int n);
void main()
{
int n;
clrscr();
printf("Enter the number:\n\n");
scanf("%d",&n);
printf("Factorial of %d is %ld",n,factorial(n));
getch();
}
long int factorial(int n)
{
if(n<=1)
{
return(01);
}
else
{
n=n*factorial(n-1);
return(n);
}
}


Output:
Enter the number
5
Factorial of 5 is 120


Hope you liked my posts, give comments if you have any doubts.. :)

Related Posts :



Categories: ,

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Related Posts with Thumbnails