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?

Printable View

- 03-28-2013, 10:04 PMrhym1nfor, 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? - 03-28-2013, 11:47 PMjim829Re: 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 - 03-29-2013, 12:42 AMrhym1nRe: for, do, print question
Thank you Jim.

Is that a large spam post by spyphone? lol - 03-29-2013, 04:10 AMDarrylBurkeRe: for, do, print question