7 Write a java program to first 20
Tribacci series [Note . A tribonacci series is one in which the sum next term is the sum of previous three terms Ex÷ 0,1,2,3,6,11,20
Answers
Answered by
0
Answer:
import java.io.*;
class GFG {
// Recursion Function
static int printTribRec(int n)
{
if (n == 0 || n == 1 || n == 2)
return 0;
if (n == 3)
return 1;
else
return printTribRec(n - 1) +
printTribRec(n - 2) +
printTribRec(n - 3);
}
static void printTrib(int n)
{
for (int i = 1; i < n; i++)
System.out.print(printTribRec(i)
+" ");
}
// Driver code
public static void main(String args[])
{
int n = 10;
printTrib(n);
}
}
// This code is contributed by
Output :
0 0 1 1 2 4 7 13 24 44
Similar questions
Physics,
2 months ago
History,
2 months ago
Math,
4 months ago
Sociology,
4 months ago
Social Sciences,
9 months ago
Social Sciences,
9 months ago
Social Sciences,
9 months ago