||
最小值:minval
最大值:maxval
【举例1】
program minmax
implicit none
real(8)::L(3)
integer i
open(unit=3,file="data.in")
do i=1, 3, 1
read(3,*) L(i)
end do
write(*,*) "the minimum value: ", minval(a)
write(*,*) "the maximum value: ", maxval(a)
end
【举例2】
program minmax2
implicit none
real(8)::L(3),M(3)
real(8)::Lmin,Mmin ! 判断L最小值,提取对应的M
real(8)::Lmax,Mmax ! 判断L最大值,提取对应的M
integer i
open(unit=3,file="data.in")
do i=1, 3, 1
read(3,*) L(i),M(i)
end do
Lmin=L(1)
Lmax=L(1)
do i=2,3,1
Lmin=min(Lmin,L(i))
Lmax=max(Lmax,L(i))
if(Lmin=L(i)) then
Lmin=L(i)
Mmin=M(i)
end if
if(Lmax=L(i)) then
Lmax=L(i)
Mmax=M(i)
end if
write(*,*) "the minimum value of L: ", Lmin
write(*,*) "the corresponding value of M:", Mmin
write(*,*) "the maximum value of L: ", Lmax
write(*,*) "the corresponding value of M:", Mmax
end
【参考资料】
fortran 怎么找一组数中最小值_百度知道 (baidu.com) 的回答
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-17 11:22
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社