I have such a formula:
I'm tryging to learn how to implement recursion in C, and wrote this code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int a(int n)
{
if(n == 0)
return 0;
if(n == 1)
return 1;
if(n%2 == 0)
return a(2*(n-1)) + a(2*(n-2));
if(n%2 != 0)
return a(2*n) - a(2*(n-1));
}
int main()
{
int n = 3;
printf("%d\n", a(n));
return 0;
}
However, my code gives me segmentation fault, what's the problem?

printf("n = %d\n", n);at the beginning of theafunction. Then run your program again and you will find out what happens.