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){intterm,t1=a,t2=b,t3=c;if(n==1)term=t1;elseif(n==2)term=t2;elseif(n==3)term=t3;else{for(inti=4;i<=n;i++){term=t1+t2+t3;t1=t2;t2=t3;t3=term;}}returnterm;}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 →