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:30

SEE, THESE KIDS DON'T READ THEIR SICP

Prelude Data.List> let hw = (mapM_ print).tail.inits.enumFromTo 1
Prelude Data.List> hw 4
[1]
[1,2]
[1,2,3]
[1,2,3,4]

Name: Anonymous 2010-04-17 17:38

whats SICP?

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';
   }
}

Name: Anonymous 2010-04-17 17:42

Even better, but uglier.

Prelude Data.List> let hw x = mapM_ (\xs -> (mapM_ (putStr.show) xs) >> putStrLn "") (tail.inits $ enumFromTo 1 x)
Prelude Data.List> hw 5
1
12
123
1234
12345
Prelude Data.List>

Name: Anonymous 2010-04-17 17:45

if you can't figure this out, just give up now.

Name: Anonymous 2010-04-17 17:57

>>4
Ack.  count>>'\n'; should be cout>>'\n';.

Name: Anonymous 2010-04-17 17:57

Unrelated question; why do C/C++ programmers like to put the incrementing variable definition outside of the for statement?

int i = 0;
for (; i < 5; i++) {

rather than

for (int i = 0; i < 5; i++) {

Name: Anonymous 2010-04-17 17:59

op here

#4 thank you

#6 I'm new and you're a dick

#8 I was taught to do it the second way you show there.

Name: Anonymous 2010-04-17 18:06

>>9
Excuse me, I was under the impression that >>8 was addressed to C/C++ programmers, so why did you reply?

Name: Anonymous 2010-04-17 18:15

>>10

Because he asked a C++ question in my thread about C++ in which I asked a question about C++


You're excused.  You're also not very helpful.

Name: Anonymous 2010-04-17 18:21

>>8
Historical reasons. I thought C++ was always exempt from it, but I have a rule against reading other people's Sepples code.

Name: Anonymous 2010-04-17 18:27

>8
variable declarations in for statement are only valid in C99, not older C89/C90 or earlier nonstandard versions of C (and Visual C++ doesn't support C99 at, just something like C89/C90 and C++98/1x)

>9,11
stop whining

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