You are viewing a single comment's thread. Return to all comments →
//using globle variable int a; int b; int c; int r(int s){ if(s==1) return a; if(s==2) return b; if(s==3) return c; return(r(s-3)+r(s-2)+r(s-1)); } int main() { int n; scanf("%d %d %d %d", &n, &a, &b, &c); printf("%d",r(n)); 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
include
include
include
//using globle variable int a; int b; int c; int r(int s){ if(s==1) return a; if(s==2) return b; if(s==3) return c; return(r(s-3)+r(s-2)+r(s-1)); } int main() { int n; scanf("%d %d %d %d", &n, &a, &b, &c); printf("%d",r(n)); return 0; }