program q8p1 implicit none integer,dimension(4:7,2:3)::y integer::i,j,k character(7)::line = "cloud 9" do i = 4,7 do j = 2,3 y(i,j) = i + 100*j end do end do 10 print*,y(6,3) 20 print*,y(9,2) read(line,'(6x,bz,i2)')k 30 print*,k end program -------------------------------------------------- 306 305 90 -------------------------------------------------- program q8 implicit none interface integer function frst_pos(a) ! returns the position of the first positive entry in the array a ! returns -1 if there is no positive entry in the array a real,dimension(:),intent(in)::a end function end interface real,dimension(9)::x x = (/0,-3,0,0,4,-3,0,-1,-2/) print*,frst_pos(x) x = (/0,-3,0,0,-4,-3,0,-1,-2/) print*,frst_pos(x) x = (/0,-3,0,0,4,-3,0,-1,-2/) print*,frst_pos(x) end program integer function frst_pos(a) implicit none real,dimension(:),intent(in)::a integer,parameter::failure = -1 integer::i = 0 do if (i > size(a) .or. a(i) > 0) exit i = i + 1 end do if (i <= size(a)) then frst_pos = i else frst_pos = failure end if end function -------------------------------------------------- The function actually has three errors. I gave you full credit if you correctly identified any one of the three errors. The first error is that it evaluates a(0), which is illegal, since the first value of an array in fortran is in position 1 unless otherwise specified. This error will go undetected if the compiler initializes all memory locations to be zero or negative. However, if the value the program obtains when it fetches a(0) is positive, the function will return the incorrect value 0. To fix this, initialize i to be 1 instead of 0. The second error is that it might evaluate a(size(a)+1), which is illegal since the array is only defined for indices up to size(a). This error will never be detected because, regardless obtained when the program fetches a(size(a)+1), the condition will be true and the loop will exit. The third error is that, since i is initialized in its specification, its value will be retained for the next function call. This error will probably be detected if the function is called more than once. For example, if the above program is executed, the output will be: 5 -1 -1 The last output is incorrect, and the reason is that the second call to the function causes i to become 10, and it is not reinitialized to 1 during the third call. Here is corrected code for the function: integer function frst_pos(a) implicit none real,dimension(:),intent(in)::a integer,parameter::failure = -1 integer::i logical::stop i = 1 stop = .false. do if (i > size(a)) then stop = .true. frst_pos = failure else if (a(i) > 0) then stop = .true. frst_pos = i end if if (stop) exit i = i+1 end do end function