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){intarr[30]={a,b,c};inti=0;intsum=0;intsum1=0;if(n==1){returna;}elseif(n==2){returnb;}elseif(n==3){returnc;}else{for(;i<n-3;i++){sum=arr[i+2]+arr[i+1]+arr[i];arr[i+3]=sum;sum1=arr[i+3];}returnsum1;}}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 →
Pointerless Solution: