Can you find 10th, 21st, 50th, 101st and 1000th element in this pattern?
Answer
0,2,1,4,1,6,2,8,…………
- Fibonacci series - http://www.mathsisfun.com/numbers/fibonacci-sequence.html
2. Even number series
_,2,_,4,_,6,_,8……
All the even count elements will be from even number series and odd count elements will be from Fibonacci series.
21st element will be (21+1)/2 =11th fibonacci number -55
50th element will be 50/2 =25th even number -50
101st element will be 101+1/2 =51st Fibonacci number – 12586269025
1000th element will be 1000/2=500th even number -1000
{
long i=0,k = 0;
long j = 1;
if (n == 1)
return 0;
if (n == 2)
return 1;
for (long count= 3; count <= n; count++)
{
k = i + j;
i = j;
j = k;
}
return k;
}
No comments:
Post a Comment