Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2008-04-22 06:46:23

chetah
Member
Registered: 2008-02-15
Posts: 32

Discrete Maths [Pseudocode]

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

#2 2008-04-22 06:52:05

Ricky
Moderator
Registered: 2005-12-04
Posts: 3,791

Re: Discrete Maths [Pseudocode]

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

#3 2008-04-22 10:24:08

John E. Franklin
Member
Registered: 2005-08-29
Posts: 3,588

Re: Discrete Maths [Pseudocode]

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

Board footer

Powered by FluxBB