Computer Science, asked by hirakhan24, 2 months ago

11. Write a program to read the number n via the Scanner class and print the Tribonacci series:
0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81 ...and so on.
Hint: The Tribonacci series is a generalisation of the Fibonacci sequence where each term is the sum of the three
preceding terms.​

Answers

Answered by parthu2011
2

Answer:

answer is in python

Explanation:

# A simple recursive CPP program to print  

# first n Tribinacci numbers.  

 

def printTribRec(n) :  

   if (n == 0 or n == 1 or n == 2) :  

       return 0

   elif (n == 3) :  

       return 1

   else :  

       return (printTribRec(n - 1) +  

               printTribRec(n - 2) +

               printTribRec(n - 3))  

         

 

def printTrib(n) :  

   for i in range(1, n) :  

       print( printTribRec(i) , " ", end = "")  

         

 

# Driver code  

n = 10

printTrib(n)  

 

Answered by tiwarishashwat125
2

Answer:

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;

 }

}

}

MARK IT AS BRAINLIEST

Similar questions