! Adapted from http://www.aspire.cs.uah.edu/textbook/fortran8012.html ! This program uses a function to find the average of three numbers. PROGRAM func_ave ! Type variables in main program (a, b, and c are local variables). REAL :: a,b,c,average ! Prompt for and get numbers to be averaged. PRINT *,"Enter the three numbers to be averaged." READ *, a,b,c ! Invoke function average PRINT *,"The three numbers to be averaged are ",a,b,c PRINT *,"The average of the three numbers is ", average(a,b,c) STOP END PROGRAM func_ave ! Function average REAL FUNCTION average(x,y,z) ! Type variables in function (x, y, and z are local varialbes). REAL :: x,y,z ! Function name contains the average the function calculates and returns. average = (x + y + z)/3.0 RETURN END FUNCTION average