Fortran Please You are given a main Fortran code called main.f90 program main us
ID: 672578 • Letter: F
Question
Fortran Please
You are given a main Fortran code called main.f90
program main
use sort_module
implicit none
integer :: n=10
real,dimension(1:10) :: a = (/8,19,1,39,5,33,45,51,69,70/)
print *,'Unsorted array : ',a
call sort(a,n)
print *, ' Sorted array : ', a
end program main
Write a subroutine and put it inside a module. Save the file as sort.f90, which takes an Integer array of dimension n and return the array in ascending order.
Write the subroutine such that you call sort(a,n,ai), where ai is the dimension of the same length as a and contains the original location of the array elements in the unsorted array
Explanation / Answer
PROGRAM ArraySort
INTEGER, PARAMETER :: UPPER_LIMIT = 40
INTEGER, DIMENSION (1:UPPER_LIMIT) :: UserIp
INTEGER :: ArrayLimit
INTEGER :: j
READ(*,*) ArrayLimit, (UserIp(j), j = 1, ArrayLimit)
CALL sort(UserIp, ArrayLimit)