fibonacci sequence help!!

Pages: 12
um so

for (i=2;i<21;i++)
{
fib[i]=fib[i-1]+fib[i-2]; <---regular fibonacci sequence..


if (i==2*i-1) <--if it is every other number then pring out the fib sequence
{
std::cout << " " << fib[i-1]+fib[i-2]<<endl;
}
else
{
std::cout << " " <<endl;
}
}



why doesnt this work????
Because this equation is never true?

i==2*i-1

(do you know your operator precedence rules?

2 * 3 + 1 = ?
a) 7
b) 8

???)

P.S. Actually, I'm not sure what your little equation is supposed to do?
Last edited on
like... if i= every other number then print out that number in the sequence?
term # 1 ,3, 5, 7 is what i want and the actual number for that term
neither do i... and where did you get this "if (i==2*i-1)" ????

in my example, i put this only to separate the numbers with a comma and a "{}" on the begin and end of the sequence
it says if 'i' is equal the size of the vector less one, will be putted a space before show the last nuber of the requested sequence..

give another look at my previous example!!!

http://cplusplus.com/forum/beginner/47776/#msg259424
im just unsure of what seq.resize(y); is .. resize for what?
closed account (D80DSL3A)
Check out how integer division works. The modulo operator % gives a remainder so:
if( i%2 ) will be true when i is an odd number.

Also, sorry you couldn't make the formula from my previous post work. It's accurate.
sqr1987 - did you get your code sorted? It would be nice to know the outcome!

Andy

P.S. seq.resize(y) sets the length of seq to y elements
Topic archived. No new replies allowed.
Pages: 12