-1
#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?

Willeke
  • 14,578
  • 4
  • 19
  • 47
Combospirit
  • 313
  • 1
  • 2
  • 11

1 Answers1

-1
long int fact(int n)
{
    return n==1? 1 : n*fact(n-1);
}
abelenky
  • 63,815
  • 23
  • 109
  • 159