Possible Duplicate:
Interview question:f(f(n)) == -n
Like I wrote above, implement a function whose prototype is
int foo(int n);
such that foo(foo(x))
returns -x
Possible Duplicate:
Interview question:f(f(n)) == -n
Like I wrote above, implement a function whose prototype is
int foo(int n);
such that foo(foo(x))
returns -x
int foo(int n)
{
static int called = 1;
if (called == 2)
{
called = 1;
return n;
}
else
{
called = 2;
return -n;
}
}