You are not logged in.
Pages: 1
for i : = 1 to 20 do
for j := 1 to i do
for k := i to j do
for m := 1 to k do
print (i * j)
I am not interested in an answer, I am able to type in to Java and see what the answer is. I want some ideas in relation to the approach in solving this problem in an examination.
Offline
What is the problem?
"In the real world, this would be a problem. But in mathematics, we can just define a place where this problem doesn't exist. So we'll go ahead and do that now..."
Offline
The k equals i to j will give an error message unless
you are allowed to have j below i in your language.
The way to reason this out is to do a lot of little
programs that solve things, and get good at it.
And use "print" statements to see what happens
when you debug.
Then later, you can think the program thru because
you know the inner loop goes around all the time,
and the middle loop goes around less, and maybe
you can see that the inner loop goes around a certain
multiple more than the other loops.
Like take this one:
for slow=1 to 3
for medium=5 to 7
for fast = 8 to 9
print slow;medium;fast
end loop
end loop
end loop
It would print this out:
158
159
168
169
178
179
258
259
268
269
278
279
358
359
368
369
378
379
good luck, ask more questions if have'm.
igloo myrtilles fourmis
Offline
Pages: 1