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.
module procedures
implicit none
contains
subroutine printArray (darray)
real, dimension (:,:), intent(inout) :: darray
integer :: s1, s2
integer :: i, j
s1 = size(darray,1)
s2 = size(darray,2)
print *, s1,s2
do i = 1, s1
do j = 1, s2
print*, "darray(",i,",",j,") = ", darray(i,j)
end do
end do
end subroutine printArray
subroutine calculateArray (K,L,Z)
real, dimension (:,:), intent(inout) :: K,L,Z
integer :: s1, s2
integer :: i, j
s1 = size(K,1)
s2 = size(K,2)
do i = 1, s1
do j = 1, s2
! read*,darray(i,j)
! ovo treba uključiti
Z(i,j)=K(i,j)-L(i,j)
end do
end do
end subroutine calculateArray
subroutine fillArray (darray)
real, dimension (:,:), intent(inout) :: darray
integer :: s1, s2
integer :: i, j
s1 = size(darray,1)
s2 = size(darray,2)
print *, s1,s2
do i = 1, s1
do j = 1, s2
! read*,darray(i,j)
! ovo treba uključiti
darray(i,j)=1
print*, "darray(",i,",",j,") = ", darray(i,j)
end do
end do
end subroutine fillArray
! this function computes the area of a circle with radius r
function aritSredina (darray)
! function result
implicit none
! dummy arguments
real :: aritSredina
! local variables
real, dimension (:,:), intent(inout) :: darray
integer :: s1, s2
integer :: i, j
real :: sredina
sredina = 0
s1 = size(darray,1)
s2 = size(darray,2)
do i = 1, s1
do j = 1, s2
sredina = sredina + darray(i,j)
end do
end do
aritSredina = sredina / (s1 * s2)
end function aritSredina
end module
program dynamic_array
use procedures
implicit none
!rank is 2, but size not known
real, dimension (:,:), allocatable :: darray
real, dimension (:,:), allocatable :: K,L,Z
integer :: s1, s2
integer :: i, j
real :: sredina
print*, "Enter the size of the array:"
! read*, s1, s2
! Ovaj read treba odkomentirati u pravom programu i komentirati treba s1,s2
! Kompajler ima problema sa standarnim inputom pa s1 i s2 postavljam ovdje ručno
s1 = 4
s2 = 4
! allocate memory
allocate ( K(s1,s2) )
allocate ( L(s1,s2) )
allocate ( Z(s1,s2) )
call fillArray(K)
call fillArray(L)
call printArray(K)
call printArray(L)
call calculateArray(K,L,Z)
call printArray(Z)
print *, ""
print *, "Aritmetička sredina matrice Z je ", aritSredina(Z)
deallocate (K)
end program dynamic_array
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more