Skip to main content

6.15) Solving The Task


Answer: The answer is 23.1.

The following program solves the problem. Please see the video that follows that explains this program.

program sol4
integer :: i
real :: t(5)    ! array to hold 5 temperature values
real :: alltemp ! variable that will be the sum of all temps.
real :: avtemp  ! variable that will be the sum of all temps.
open(15,file='temp.dat')
open(16,file='outtemp.dat')
! read in the values from the data file
do i=1,5
    read(15,*) t(i)
enddo
! compute the average temperature
alltemp=0.
do i=1,5
    alltemp=alltemp + t(i)
enddo
avtemp=alltemp/5.0
! output the result to the file outtemp.dat
write(16,*) avtemp
end program sol4