Q3
Q3
implicit none
integer :: i, j, n, temp
integer, allocatable, dimension(:) :: ar
read(*,*) n
open(unit=2, file='ar_inp.txt')
12 format(i2)
if(n>=5) then
allocate(ar(0:n-1))
read(*, *) (ar(i), i=0, n-1)
write(2, 12) (ar(i), i=0, n-1)
else
write(*,*) "Error: n < 5"
end if
close(2)
open(unit=5, file='ar_out.txt')
close(5)
end program
do i=0, n-2
do j=i+1, n-1
if(ar(i) > ar(j)) then
temp = ar(i)
ar(i) = ar(j)
ar(j) = temp
end if
end do
end do
end subroutine
end subroutine