5 Replies - 275 Views - Last Post: 20 March 2011 - 07:23 PM Rate Topic: -----

#1 opawix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 20-March 11

Displaying a Sequence

Posted 20 March 2011 - 04:41 PM

here are my codes:

#include<iostream>
using namespace std;
int main()
{
    int x;
    
      for(x=3; x=47; x++)
      {
               cout<<x;
               }
         system("pause");
         return 0;
         }




programs counts 3 to 47 but i want to do it by increasing its increment so it will output like this: 3 5 6 12 17 23 30 38 47. any help guys? thanks a lot.

Edited by Martyn.Rae: Added code tags. :code:.

Edited by macosxnerd101: Renamed title to be more descriptive.

Is This A Good Question/Topic? 0
  • +

Replies To: Displaying a Sequence

#2 TMKCodes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 48
  • View blog
  • Posts: 440
  • Joined: 21-March 09

Re: Displaying a Sequence

Posted 20 March 2011 - 04:47 PM

Modify the x++ to something like x+=2 or x+=3.. You can even use another variable for the assignment addition.
Was This Post Helpful? 0
  • +
  • -

#3 opawix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 20-March 11

Re: Displaying a Sequence

Posted 20 March 2011 - 04:58 PM

ya i tried dat already but fail. tsk! :whistling: it cout the execution of counting 3 t0 47 then cout the x+1 too.
Was This Post Helpful? 0
  • +
  • -

#4 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1304
  • View blog
  • Posts: 4,488
  • Joined: 19-February 09

Re: Displaying a Sequence

Posted 20 March 2011 - 05:40 PM

Perhaps the sequence you mean is :-
3, 5, 8, 12, 17, 23, 30, 38, 47.
Which has an eight instead of a six.
That is much easier.

Does this code work, the middle part x=47 should be a boolean expression.

for(x=3; x=47; x++)


Was This Post Helpful? 0
  • +
  • -

#5 opawix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 20-March 11

Re: Displaying a Sequence

Posted 20 March 2011 - 05:57 PM

View Post#define, on 20 March 2011 - 05:40 PM, said:

Perhaps the sequence you mean is :-
3, 5, 8, 12, 17, 23, 30, 38, 47.
Which has an eight instead of a six.
That is much easier.

Does this code work, the middle part x=47 should be a boolean expression.

for(x=3; x=47; x++)



ok2 i add x<=47. but still executes 3 to 47 not the sequence you just have corrected.
Was This Post Helpful? 0
  • +
  • -

#6 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1304
  • View blog
  • Posts: 4,488
  • Joined: 19-February 09

Re: Displaying a Sequence

Posted 20 March 2011 - 07:23 PM

Try calculating the difference between each adjacent pair of numbers, in the sequence.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1