Tribonacci Numbers

import java.io.*;
class Tribonacci
{
public static void main() throws IOException
{
InputStreamReader x= new InputStreamReader(System.in);
BufferedReader y= new BufferedReader(x);

System.out.println(“Enter the number of Tribonacci Terms to be printed”);
int n = Integer.parseInt(y.readLine());
int f=0,s=1,t=1,fr=0,i;
for(i=1;i<=n;i++)
{
System.out.print(f + ” , “);
fr=f + s + t;
f = s;
s = t;
t = fr;
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s