[Fortran] 纯文本查看 复制代码
program test
Implicit none
integer::n
real, allocatable:: a(:),b(:)
Print*, '输入一维数组元素个数n:'
Read*, n
allocate(a(n), b(n))
Print*, '输入数组a的各元素值:'
Read*, a
call sort(a,b)
Print'(a, <n>f7.3)', '排序前a=', a
Print'(a, <n>f7.3)', '排序后b=', b
End program
subroutine sort(a, b)
integer:: m, i,j, t
real:: a(m), b(m)
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
[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