write a java program to print the tribonacci series in one in which the sum next term is the sum of previous three terms.example 0 1 2 3 4 6 11 20 ........n terms
Answers
Answered by
6
Answer:
tribonacci series is one in which the sum next term is the sum of previous three terms
Example 0 1 2 3 6 11 20………….
import java.util.Scanner;
public class Tribonacci
{
public static void main(String args[]) {
func(10);
}
static void func(int n) {
int a = 0, b = 1, c = 2, d = 0, i;
System.out.print(a + " , " + b + " , " + c);
for (i = 4; i <= n; i++) {
d = a + b + c;
System.out.print(", " + d);
a = b;
b = c;
c = d;
}
}
}
Output:
0 , 1 , 2, 3, 6, 11, 20, 37, 68, 125
BUILD SUCCESSFUL (total time: 1 second)
Similar questions
English,
3 months ago
Math,
3 months ago
English,
6 months ago
Social Sciences,
10 months ago
History,
10 months ago
Social Sciences,
10 months ago