/**
* class tribonacci_series prints the Tribonacci Series
* Tribonacci Series: 0,1,1,2,4,7,13,24,44,81
* @author: NItendra Kumar
* @version :May 21/2013
*/
import java.util.Scanner;
public class tribonacci_series
{
public static void main()
{
Scanner in=new Scanner(System.in);
System.out.println("Enetr the limit");
int limit=in.nextInt();
int num1,num2,num3,sum;
num1=0;
num2=1;
num3=1;
System.out.print(num1 +"," +num2+","+num3+",");
for(int i=0;i<limit;i++)
{
sum=num1+num2+num3;
num1=num2;
num2=num3;
num3=sum;
System.out.print(sum+",");
}
}
}
Output:
Enter the limit
10
0,1,1,2,4,7,13,24,44,81,149,274,504,
/*---------------Program developed by: Nitendra Kumar---------------*/
//For more details visit http://javawithnitendra.blogspot.in
No comments:
Post a Comment
Ur comments r most welcome...