Im a student & and just started learning c++...
My professor assigned me a program to get output as:

1 1 2 3 5 8 13 21 34

With the use of while loop...

i hv made this>>

#include<iostream.h>
#include<conio.h>
main()
{

      int n=1,m=2;
      cout<<n<<' '<<n<<' '<<m<<' '<<n+m<<' '<<n+(2*m)<<' '<<4*m<<' '<<n+(6*m)<<' '<<n+(10*m)<<' '<<(17*m);
      getch();
}


>>>>>>>>>>>>>>>>



  Any help?
  to make it using while__?

I think you might want to read up on The F sequence! :D to understand what's the sequence actually meaning and not random variables multiplied with integers ..

Edited 1 Year Ago by Slavi

Something like this?

const int numberOfTerms = 9; //your homework mentions 9 terms.
int counter = 0;
while (counter < numberOfTerms)
{
    //calculate Fib. term
    //output Fib. term
    counter++;
}

It looks like your professor wants you to print out the fibonacci sequence. I'll give you a hint. The Fibonacci sequence starts like this
0
1
1
2
3
5
8
13
21
34
55
and so forth
What you are doing is you are adding the last two numbers. So it starts out as 0, 0 has nothing, so it goes up to 1.
Now, we have 0 and 1. We can add them together and get 1.
Now we have 0 1 1, so now we can add 1 and 1 and get 2
Now we have 0 1 1 2, so we can add 1 and 2 and get 3
Now we have 0 1 1 2 3, so we can add 2 and 3 and get 5
Now we have 0 1 1 2 3 5, so we can add 3 and 5 and get 8

And so forth and so forth.
Does that make sense?
If you can get that idea, you can code it

This article has been dead for over six months. Start a new discussion instead.