Skip to content

Commit 2bc3e3f

Browse files
Create CalculateTheNthTerm.c
1 parent 087529e commit 2bc3e3f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Functions/CalculateTheNthTerm.c

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
#include <math.h>
4+
#include <stdlib.h>
5+
6+
int find_nth_term(int n, int a, int b, int c) {
7+
if (n == 1) return a;
8+
if (n == 2) return b;
9+
if (n == 3) return c;
10+
else return(find_nth_term(n-1, a, b, c) + find_nth_term(n-2, a, b, c) + find_nth_term(n-3, a, b, c));
11+
}
12+
13+
14+
int main() {
15+
int n, a, b, c;
16+
17+
scanf("%d %d %d %d", &n, &a, &b, &c);
18+
int ans = find_nth_term(n, a, b, c);
19+
20+
printf("%d", ans);
21+
return 0;
22+
}

0 commit comments

Comments
 (0)