Skip to content

Commit 4632d6f

Browse files
authored
Create: 1137-n-th-tribonacci-number.c
1 parent 53ccafb commit 4632d6f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

c/1137-n-th-tribonacci-number.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
int tribonacci(int n) {
2+
if (n == 0)
3+
return 0;
4+
else if (n == 1 || n == 2)
5+
return 1;
6+
7+
int trib[n + 1];
8+
trib[0] = 0;
9+
trib[1] = 1;
10+
trib[2] = 1;
11+
12+
for (int i = 3; i <= n; i++) {
13+
trib[i] = trib[i - 1] + trib[i - 2] + trib[i - 3];
14+
}
15+
16+
return trib[n];
17+
}

0 commit comments

Comments
 (0)