Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++

Name: Anonymous 2010-04-17 17:20

For an assignment I need to have a program print the inputted number, and every number before it in sequence ex:

1
12
123
1234
12345
123456

I can get it to print a list of the number but for the love of god I cant get it to print the numbers before hand.  I know theres a simple way to do it nesting a while loop in a for loop but I can't fucking figure it out.

Help for a poor retarded aspiring programmer?

Name: Anonymous 2010-04-17 17:40

Should I?  I shall, shalln't I?  I'm going jump ahead and assume you start at 1 always.

//x is the input
int i = 1, j = 1;
for(; i <= j && j <= x; i++)
{
   cout>>i;
   if(i == j)
   {
      i = 1;
      j = j + 1;
      count>>'\n';
   }
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List