# Thread: for, do, print question

1. Member
Join Date
Feb 2013
Posts
32
Rep Power
0

## for, do, print question

Consider the following program segment (written in pseudocode):

for i := 1 to 123 do
for j := 1 to i do
print i*j

How many times is the print statement of the third line executed?

2. Senior Member
Join Date
Jan 2013
Location
United States
Posts
2,726
Rep Power
4

## Re: for, do, print question

Well, the first time thru is 1, the second time thru is 2. So far 1 + 2 = 3. Then third time thru is 3. So 1 + 2 + 3 = 6.
So summing the numbers from 1 to n is equal to (n)(n+1)/2 where in this case, n = 123. The answer should be 7626.

Regards,
Jim

3. Member
Join Date
Feb 2013
Posts
32
Rep Power
0

## Re: for, do, print question

Thank you Jim.

Is that a large spam post by spyphone? lol

4. ## Re: for, do, print question

Originally Posted by rhym1n
Is that a large spam post by spyphone? lol
Please don't comment on or respond to spam, as your post goes out of context when the spam is removed.

db

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•