Write a program to write Tribonacci series.
import java.util.Scanner; public class TribonacciSeries { public static void main(String[] args) { int x=-1,y=1,z=0; Scanner sc=new Scanner(System.in); System.out.println("Enter a Number:-"); int n=sc.nextInt(); System.out.println("The tribo series is:- "); triboSeries(n,z,x,y); } private static void triboSeries(int x,int f,int f1,int f2) { if(x==0) System.exit(0); System.out.print(" " + (f+f1+f2)); triboSeries(--x,f1,f2,f+f1+f2); } } OUTPUT: Enter a Number:- 10 The tribo series is:- 0 0 1 1 2 4 7 13 24 44 Enter a Number:- 8 The tribo series is:- 0 0 1 1 2 4 7 13
No comments:
Post a Comment