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){//Write your code here.if(n==1)returna;elseif(n==2)returnb;elseif(n==3)returnc;else{intsum=0;for(inti=1;i<=n-3;i++){sum=a+b+c;a=b;b=c;c=sum;}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 →
I think it is better way !