In the following code, my last statement in main function is return fact(n) does not work.
But if I substitute it with printf ("Factorial of %d = %d\n", n, fact(n)); it works
My question is if main function expects int as return value, why does the first option not work?
#include <cs50.h>
#include <stdio.h>
int fact (int n)
{
if (n==0)
return 1;
if (n == 1)
return 1;
else
return n* fact(n-1);
}
int main(void)
{
int n;
printf ("Enter your number for whose factorial you want? \n");
scanf ("%d", &n);
return fact(n);
}