#include <stdio.h>
long int fact(int n);
int main()
{
int n;
printf("Enter number\n");
scanf("%d",&n);
printf("Factorial:%ld\n",fact(n));
return 0;
}
long int fact(int n)
{
if(n!=1)
return n*fact(n-1);
}
I'm trying to get the factorial of a number with recursion.But I'm getting 0 as the result everytime. What's wrong with this code?