Pell series program in java
Answers
Pell Number
Pell numbers are numbers that are similar to the Fibonacci numbers and are generated by below formula
Pn = 2*Pn-1 + Pn-2
with seeds P0 = 0 and P1 = 1
First few Pell numbers are 0, 1, 2, 5, 12, 29, 70, 169, 408, 985, 2378, 5741, 13860, 33461, ….
Write a function int pell(int n) that returns Pn.
Examples:
Input : n = 4
Output :12
Input : n = 7
Output : 169
that was help?
Answer:
pell series- 0, 1 , 2, 5, 12…
so basically the number multiplied by 2 plus the number before it eg -1*2+0=2 and 5*2+2= 12.
the first two numbers are 0 &1
the program note- add the class and packages before
{int first=0, second=1, third , number, loop;
system.out.print(first+"\n"+second);
for (i=1;i<=n-2,i++) /*its n-2 because 0&1 are already printed */
{third=second*2+first:
system.out.print(\n+t);
frist=second
second=third}}