Fortran: Lesson 5

Lesson topics


View Demos
# 1 # 2 # 3
Download Demos
# 1 # 2 # 3

Demo 2

								        program mean
c       This program computes the mean of a list of numbers.
c       A function subprogram finds the mean. 
        real numbers(100), avg
        integer m
        print *, "How many numbers are on your list?"
        print *, "(no more than 100, please)"
        read *, m
        do i = 1, m
                print *, "Enter your next number:"
                read*, numbers(i)
        end do
        print *, "The average is", avg(m,numbers)
        print *, "Goodbye"
        end

        function avg(n,list)
        real avg, list(100), sum
        integer n
        sum = 0
        do i=1, n
                sum = sum + list(i)
        end do
        avg = sum/n
        end