- Thread starter
- #1

#### find_the_fun

##### Active member

- Feb 1, 2012

- 166

for i := 1 to 12 do

for j := 5 to 10 do

for k := 15 downto 8 do

printf (i-j)*k

How many time is the print statement executed?

I thought it would be 12x5x7 but the answer key has 576?

- Thread starter find_the_fun
- Start date

- Thread starter
- #1

- Feb 1, 2012

- 166

for i := 1 to 12 do

for j := 5 to 10 do

for k := 15 downto 8 do

printf (i-j)*k

How many time is the print statement executed?

I thought it would be 12x5x7 but the answer key has 576?

- Jan 30, 2012

- 2,502

See off-by-one error in Wikipedia.

- Thread starter
- #3

- Feb 1, 2012

- 166

Isn't the question ambiguous? For example "for i := 1 to 12" you don't know if another iteration will occur at 12 i.e. you don't know if it's i < 12 or i <= 12

See off-by-one error in Wikipedia.

- Jan 30, 2012

- 2,502

Code:

```
do i=1,10
print*,i**2
end do
```

- Admin
- #5

- Jan 26, 2012

- 4,052