Explanations%20of%20midterm%20winter%202008

# Explanations%20of%20midterm%20winter%202008 - Question 6...

This preview shows pages 1–3. Sign up to view the full content.

Question 6 What is the output of the following Fortran program? PROGRAM MIDTERM IMPLICIT NONE INTEGER :: f, array(7), i DO i=1,7 array(i) = i END DO DO i=7,2,-1 array(i/2) = f(array(8-i)) END DO WRITE (*,*) array END PROGRAM INTEGER FUNCTION f(num) IMPLICIT NONE INTEGER :: num num = num + 1 f = mod(num,2) END FUNCTION 1 1 1 4 5 6 7 1 1 2 5 6 7 7 1 2 3 4 5 6 7 1 1 2 5 6 7 8 None of the above Answer: None of the above Explanation: After the first loop array() contains: array(1) array(2) array(3) array(4) array(5) array(6) array(7) 1 2 3 4 5 6 7 This is what happens during the second loop: Loop Calculations array(1. .7) I = 7 array(3)=f(array(1)) This will happen:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
In Function: array(1)=array(1)+1=2 f = mod(2,2) = 0 Back to the program: array(3)=0 New values for array()=> 2 2 0 4 5 6 7 I = 6 array(3)=f(array(2)) This will happen: In Function: array(2)=array(2)+1=3 f = mod(3,2) = 1 Back to the program: array(3)=1 New values for array()=> 2 3 1 4 5 6 7 I = 5 array(2)=f(array(3)) This will happen: In Function: array(3)=array(3)+1=2 f = mod(2,2) = 0 Back to the program: array(2)=0
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 01/15/2010 for the course COMP COMP 206 taught by Professor Vybihal during the Spring '04 term at McGill.

### Page1 / 4

Explanations%20of%20midterm%20winter%202008 - Question 6...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online