real function ave(a)
implicit none
real :: a(20)
integer :: i
ave=0.0
do i=1,20
ave=a(i)+ave
end do
ave=ave/20.0
end function
subroutine compare(a,b)
implicit none
real :: a(20), b(20)
real,external :: ave
if (ave(a)
end subroutine
program main
implicit none
real,external :: ave
real :: a(20), b(20)
real :: m
integer :: error
open (unit=10,file="data.txt",status="old",iostat=error)
if(error/=0) then
write(*,*) "open data.txt fail"
stop
else
read(10,*) a
read(10,*) b
end if
call compare(a,b)
write (*,*) a
end program
提前在文件data.txt文件中输入数据,格式如下
1.986,1.987,1.765,1.453,1.786...
2.976,2.654,3.7654,9.987,3.234..
我只写了五个数,放在源程序所在的文件夹中。