1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

1st year student: Tracing a program by hand

  1. Oct 18, 2009 #1
    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 (Text):
    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: Oct 18, 2009
  2. jcsd
  3. Oct 19, 2009 #2
    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=?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: 1st year student: Tracing a program by hand
  1. Fick's 1st/2nd law (Replies: 5)

  2. Program Trace [assembly] (Replies: 25)

Loading...