On line 2 : missing semi collon ";"
You appear to be doing a recursive function, but function "f()" does not exist
Maybe you want to do
return n * fact( n - 1 );
program does not detect overflow of integer.
Any input > 12 will overflow and return invalid result (on my 64 bit i7 machine running linux-64-bit)
Since factorials of integers are constant program had been been written like this, much easier to verify and much more efficient in runtime :
==========================
#include <stdio.h>
int fact(int); // forward declaration
int main(int argc, char **argv)
{
int x = 0;
printf("enter the number x: ");
scanf("%d", &x);
int res = fact(x);
if (res == -1)
{
printf("value %d is out of range too large\n", x);
}
else if (res == -2)
{
printf("value %d is out of range : negative\n", x);
}
else
{
printf("the factorial of %d is %d\n", x, res);
}
return(0);
}
int fact(int n) // return factorial of integer, negative on invalid input
{
const int results[] = {
1,
1,
2,
6,
24,
120,
720,
5040,
40320,
362880L,
3628800L,
39916800L,
479001600L,
// 6227020800L,
// 87178291200L,
// 1307674368000L,
// 20922789888000L,
};
if (n < 0)
return -2;
if (n > 12)
return -1;
return results[n];
}