Pell Series in JAVA
Pell Series
Pell Series : A series of numbers in which each number (Pell Number) is the sum of the twice the previous Pell number and the Pell number before that. It starts from 0 and 1.
The first few terms of the sequence are :-
0 1 2 5 12 29 70 169 408 985
Program to Print Pell Series given below :-
Program :-
import java.io.*;
import java.util.*;
class Pell
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int a=0,b=1,c=0,n,i;
System.out.println("Enter No. of terms");
n= in.nextInt();
System.out.println("Pell Series given below:-");
System.out.print(a+"\t");//printing first number
System.out.print(b+"\t");//printing second number
for(i=3;i<=n;i++)
{
c=(2*b)+a;
System.out.print(c+"\t");
a=b;
b=c;
}
}//end of main method
}//end of class
import java.util.*;
class Pell
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int a=0,b=1,c=0,n,i;
System.out.println("Enter No. of terms");
n= in.nextInt();
System.out.println("Pell Series given below:-");
System.out.print(a+"\t");//printing first number
System.out.print(b+"\t");//printing second number
for(i=3;i<=n;i++)
{
c=(2*b)+a;
System.out.print(c+"\t");
a=b;
b=c;
}
}//end of main method
}//end of class
For Proper Understanding Watch the Video :-
Watch this video : Pell Series
Follow me on Instagram
All the best :)
Keep Learning :)
Comments
Post a Comment