本帖最后由 li913 于 2017-6-24 20:40 编辑
[Fortran] 纯文本查看 复制代码 subroutine sort(a, b, m)
integer:: m, i,j, t
real:: a(m), b(m)
b = a !先把a整体赋给b
do i=1, m-1
do j= i+1,m
if(b(i)>b(j))then
t = b(i); b(i) = b(j); b(j) = t!交换
endif
enddo
enddo
end subroutine
subroutine sort(a, b)
integer:: m, i,j, t
real:: a(:), b(:)
m=size(a)
b = a !先把a整体赋给b
do i=1, m-1
do j= i+1,m
if(b(i)>b(j))then
t = b(i); b(i) = b(j); b(j) = t!交换
endif
enddo
enddo
end subroutine
前者比较常用,后者需要接口:http://fcode.cn/guide-103-1.html。另外,t的类型应与a一致。 |