Advertisement
Guest User

Untitled

a guest
May 5th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    integer, allocatable   :: A(:), Positives(:)
  2.    logical, allocatable    :: Pos(:)
  3.  
  4.    open (file=input_file, newunit=In)
  5.       read (In, *) M
  6.       allocate (A(M))
  7.       read (In, *) A
  8.    close (In)
  9.  
  10.    open (file=output_file, encoding=E_, newunit=Out)
  11.     write (Out, "("//M//"f6.2)") A
  12.    close (Out)
  13.  
  14.    allocate(Pos(M))
  15.  
  16.     write (*,*) Sort(A)
  17.  
  18.  
  19.    open (file=output_file, encoding=E_, newunit=Out, position='append')
  20.       write (Out, "(/"//M//"f6.2)") A
  21.    close (Out)
  22.  
  23. contains  
  24.   pure function Sort(A) result(Z)
  25.       integer   len, i, j, tmp
  26.       integer, allocatable :: Z(:)
  27.       integer, intent(in)  ::  A(:)
  28.       Z = A
  29.       len = Size(Z)
  30.       do i = 1, len
  31.          do j = 1, len - i
  32.             if (Z(j) > Z(j+1)) then
  33.                tmp = Z(j+1)
  34.                Z(j+1) = Z(j)
  35.                Z(j) = tmp
  36.             end if
  37.          end do
  38.       end do
  39.       end function Sort
  40.  
  41. end program lab_7_2a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement