- 509 名前:デフォルトの名無しさん mailto:sage [2006/06/22(木) 09:08:07 ]
- >>507
作ってみた program rndm real,dimension(:),allocatable :: x; integer :: i,n,stat read(*,*) n allocate(x(n),stat=stat) if(stat/=0) stop "could not allocate x" do i=1,n call random_number(x(i)) enddo print *,"before sort"; call printx(x) call srt(x) print *,"after sort"; call printx(x) deallocate(x) contains subroutine printx(x) real,dimension(:) :: x; integer :: i do i=1,size(x); print *,x(i); enddo end subroutine printx recursive subroutine srt(x) integer :: i,iflag; real :: tmp real,dimension(:) :: x iflag=0 do i=1,size(x)-1 if(x(i)>x(i+1)) then iflag=1; tmp=x(i); x(i)=x(i+1); x(i+1)=tmp endif enddo if(iflag/=0) call srt(x) end subroutine srt end program rndm
|

|