Tribonacci Series in JAVA

Tribonacci Series

Tribonacci Series : A Tribonacci sequence is a sequence of numbers such that each term from the fourth onward is the sum of the previous three terms.

It is similar to Fibonacci Series
 
The first few terms of the sequence are :-
 
0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, 504, 927


Program to Print Tribonacci Series given below :-


Program :-

import java.io.*;
import java.util.*;
class Tribonacci
{
    public static void main(String args[])
    {
        Scanner in = new Scanner(System.in);
        int a=0,b=0,c=1,d=0,n,i;
        System.out.println("Enter No. of terms");
        n= in.nextInt();
        System.out.println("Fibonacci Series given below:-");
        System.out.print(a+"\t");//printing first number
        System.out.print(b+"\t");//printing second number
        System.out.print(c+"\t");//printing third number
        for(i=4;i<=n;i++)
        {
            d=a+b+c;
            System.out.print(d+"\t");
            a=b;
            b=c;
            c=d;            
        }
    }//end of main method
}//end of class


For Proper Understanding Watch the Video :-



Watch this video : Tribonacci Series
 
Follow me on Instagram

All the best :)
Keep Learning :)





Comments

  1. Casinos Near Foxwoods Casino, FL - Mapyro
    MapYRO® Resort is a 제주도 출장안마 fun, friendly 거제 출장마사지 and affordable option for travelers looking 통영 출장샵 for a fun, 충청남도 출장안마 friendly place to stay 양주 출장샵 in and out of Foxwoods.

    ReplyDelete

Post a Comment

Popular posts from this blog

Frequency of each digit of a number in Java

Trimorphic Number in JAVA

Tri-Automorphic Number in JAVA