You are viewing a single comment's thread. Return to all comments →
int nthTerm(int n, int a, int b, int c) { if (n == 1) return a; if (n == 2) return b; if (n == 3) return c;
return nthTerm(n - 1, b, c, a + b + c);
}
int main() { int n, a, b, c; scanf("%d", &n); scanf("%d %d %d", &a, &b, &c);
printf("%d\n", nthTerm(n, a, b, c)); return 0;
Seems like cookies are disabled on this browser, please enable them to open this website
Calculate the Nth term
You are viewing a single comment's thread. Return to all comments →
include
int nthTerm(int n, int a, int b, int c) { if (n == 1) return a; if (n == 2) return b; if (n == 3) return c;
}
int main() { int n, a, b, c; scanf("%d", &n); scanf("%d %d %d", &a, &b, &c);
}