Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
program ex18c
!mathematical operation
real:: x,y
read *, x
if(x>-1) then
y=2*x**2+3
print *, 'the value of y is=' ,y
else
y=x-5
print *,'the value of y is=' ,y
end if
end program ex18c
program hello
implicit none
integer, dimension (:,:), allocatable :: darray
integer, target, dimension (:), allocatable :: sortarray
integer, target, dimension (:), allocatable :: narray
integer :: i, j, n, k
character (len = 15) :: input_file
character (len = 15) :: output_file
integer :: columns = 0, rows = 0, middleman = 0
!get arguments
CALL GET_COMMAND_ARGUMENT(1, input_file)
CALL GET_COMMAND_ARGUMENT(2, output_file)
print *, input_file
print *, output_file
write(*,*)input_file
!open file for reading
open (unit = 1, file = input_file, status = 'old')
read(1, *) columns, rows
!print "(i6)", columns
!print "(i6)", rows
!fill array
allocate (darray(columns,rows))
allocate (narray(columns))
allocate (sortarray(columns))
!get rows
do i = 1, rows
read(1, *) narray
print *, narray
!print *,'before = ', narray
!sort a row
do n = 1, columns
do j = 1, (columns-n)
if(narray(j) .gt. narray(j+1)) then
middleman = narray(j)
narray(j) = narray(j+1)
narray(j+1) = middleman
end if
end do
end do
do j = 1, columns
darray(j,i) = narray(j)
end do
!print *,'after= ', darray
end do
close(1)
open (unit = 2, file = output_file, status = 'new')
!sort columns
do i = 1, rows
do j = 1, (rows-i)
if(darray(1,j) .gt. darray(1,(j+1))) then
do k = 1, columns
middleman = darray(k,(j))
darray(k, j) = darray(k, (j+1))
darray(k, (j+1)) = middleman
end do
end if
end do
!print row to file
do k = 1, columns
write(2, *) darray(i,k)
end do
write(2, *) '/'
end do
!print *,'should be sorted = ', darray
close(2)
end program Hello