源代码如下:
implicit none
integer::i,j,N
real*8::x(8)
real*8::tmp
x=[1,2,3,4,5,6,7,8]
N=size(x)
do i=1,N-1
do j=i+1,N
if(x(j)>x(i))then
tmp=x(i)
x(i)=x(j)
x(j)=tmp
end if
end do
end do
do i=1,N
print *, x(i)
end do
编译、运行,结果如下:
fortran编程实现冒泡排序(由小到大)
源代码如下:
implicit none
integer::i,j,N
real*8::x(8)
real*8::tmp
x=[81,72,63,54,45,36,27,18]
N=size(x)
do i=1,N-1
do j=i+1,N
if(x(j)
tmp=x(i)
x(i)=x(j)
x(j)=tmp
end if
end do
end do
do i=1,N
print *, x(i)
end do
编译、运行、结果如下: