Advertisement
Guest User

Untitled

a guest
May 2nd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program lab_7_2a
  2.    use Environment
  3.  
  4.    implicit none
  5.    character(*), parameter :: input_file = "../data/input.txt", output_file = "output.txt"
  6.    integer                 :: In = 0, Out = 0, M = 0
  7.    real(R_), allocatable   :: A(:), Positives(:)
  8.    logical, allocatable    :: Pos(:)
  9.  
  10.    open (file=input_file, newunit=In)
  11.       read (In, *) M
  12.       allocate (A(M))
  13.       read (In, *) A
  14.    close (In)
  15.  
  16.    open (file=output_file, encoding=E_, newunit=Out)
  17.     write (Out, "("//M//"f6.2)") A
  18.    close (Out)
  19.  
  20.    allocate(Pos(M))
  21.  
  22.     write (*,*) SortBlyad(A)
  23.  
  24.  
  25.    open (file=output_file, encoding=E_, newunit=Out, position='append')
  26.       write (Out, "(/"//M//"f6.2)") A
  27.    close (Out)
  28.  
  29. contains
  30.  
  31.    subroutine SortBlyad(A)
  32.       integer, intent(inout)  :: A(:)
  33.       integer                 :: len
  34.       integer                 :: i, j, tmp
  35.  
  36.       len = Size(A)
  37.       do i = 1, len
  38.          do j = 1, len - i
  39.             if (A(j) > A(j+1)) then
  40.                tmp = A(j+1)
  41.                A(j+1) = A(j)
  42.                A(j) = tmp
  43.             end if
  44.          end do
  45.       end do
  46.       end subroutine
  47.  
  48. end program lab_7_2a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement