1st year student: Tracing a program by hand

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
BrownianMan
Messages
133
Reaction score
0
Hey, new to the forum.

I'm currently taking my first programming course, and in one of the assignments, I was asked to trace the following Fortran77 program fragment by hand and determine the final values for n and m:

Code:
integer n, m, k, j
n = 0
m = 0
do k = 1, 3
    do j = k, 1, -1
        n = n + j
    end do
    m = m + k
end do
print*, n
print*, m

I was only able to get this far:

n m k j
0 0 1 1
1 1 2 0
3 3 3 2


How should I approach it from here?
 
Last edited:
Physics news on Phys.org
You are not considering all cases

(
k=1
j=1
)
m=?
n=?

(
k=2
j=2
)
m=?
n=?

(
k=2
j=1
)
m=?
n=?

(
k=3
j=3
)
m=?
n=?

(
k=3
j=2
)
m=?
n=?

(
k=3
j=1
)
m=?
n=?