C Program to print the nth term of a series , whose one term is the sum of previous three terms using Recursion - HackerRank
// Program by Akash Tripathi (@proakash256)
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
//Complete the following function.
int find_nth_term(int n, int a, int b, int c)
{
static int i = 4;
static int s = 0;
if (i <= n)
{
s = a + b + c;
a = b;
b = c;
c = s;
i = i + 1;
find_nth_term(n , a , b , c);
}
return s;
}
int main()
{
int n, a, b, c;
scanf("%d %d %d %d", &n, &a, &b, &c);
int ans = find_nth_term(n, a, b, c);
printf("%d", ans);
return 0;
}
Comments
Post a Comment