School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,151 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,690 people online right now. Registration is fast and FREE... Join Now!




1st year student: Tracing a program by hand

 

1st year student: Tracing a program by hand

BrownianMan

18 Oct, 2009 - 09:58 AM
Post #1

New D.I.C Head
*

Joined: 18 Oct, 2009
Posts: 2

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?

User is offlineProfile CardPM
+Quote Post


olibenu

RE: 1st Year Student: Tracing A Program By Hand

18 Oct, 2009 - 10:25 AM
Post #2

D.I.C Regular
Group Icon

Joined: 31 Dec, 2008
Posts: 269



Thanked: 15 times
Dream Kudos: 350
My Contributions
is it cheating if you put breakpoints and run the program?
User is offlineProfile CardPM
+Quote Post

olibenu

RE: 1st Year Student: Tracing A Program By Hand

18 Oct, 2009 - 10:32 AM
Post #3

D.I.C Regular
Group Icon

Joined: 31 Dec, 2008
Posts: 269



Thanked: 15 times
Dream Kudos: 350
My Contributions
start from the inner most loop, that always helps me
User is offlineProfile CardPM
+Quote Post

BrownianMan

RE: 1st Year Student: Tracing A Program By Hand

18 Oct, 2009 - 10:43 AM
Post #4

New D.I.C Head
*

Joined: 18 Oct, 2009
Posts: 2

QUOTE(olibenu @ 18 Oct, 2009 - 10:32 AM) *

start from the inner most loop, that always helps me


What happens when k becomes higher than 3 though? Shouldn't it exit the loop?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 04:37PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month