Fortran中实现冒泡排序
001、
[root@localhost 03_fortran]# ls test1.f90 [root@localhost 03_fortran]# cat test1.f90 program test01_fortran implicit none integer :: i,j integer :: a(6) = [38, 32, 5, 24, 86, 23] integer :: temp do i = 1, size(a) - 1 do j = 1, size(a) - i if(a(j) > a(j + 1)) then temp = a(j) a(j) = a(j + 1) a(j + 1) = temp end if end do end do print *, "sort result: ", a end program test01_fortran [root@localhost 03_fortran]# gfortran test1.f90 -Wall -O2 -o kkk [root@localhost 03_fortran]# ls kkk test1.f90 [root@localhost 03_fortran]# ./kkk sort result: 5 23 24 32 38 86

。

浙公网安备 33010602011771号