Calculate the Nth term

  • + 0 comments

    //Copy all this code and paste it

    include

    // Recursive function to find the nth term of the series int recurse(int n, int a, int b, int c) { // Base cases if (n == 1) return a; if (n == 2) return b; if (n == 3) return c;

    // Recursive case
    return recurse(n-1, a, b, c) + recurse(n-2, a, b, c) + recurse(n-3, a, b, c);
    

    }

    int main() { int n, a, b, c;

    // Input n and the first three terms of the series
    scanf("%d", &n);
    scanf("%d %d %d", &a, &b, &c);
    
    // Output the nth term of the series
    printf("%d\n", recurse(n, a, b, c));
    
    return 0;
    

    }