We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>//Complete the following function.intfind_nth_term(intn,inta,intb,intc){intsum=0;if(n==1){sum=a;}elseif(n==2){sum=b;}elseif(n==3){sum=c;}elseif(n>3){for(inti=n-3;i<n;i++){sum+=find_nth_term(i,a,b,c);}}returnsum;}intmain(){intn,a,b,c;scanf("%d %d %d %d",&n,&a,&b,&c);intans=find_nth_term(n,a,b,c);printf("%d",ans);return0;}
Cookie support is required to access HackerRank
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 →