Answers for "arrays in fortran"

0

gfortran: declare an array

program arrayProg

   real :: numbers(5) !one dimensional real array
   integer :: matrix(3,3), i , j !two dimensional integer array
   
   !assigning some values to the array numbers
   do i=1,5
      numbers(i) = i * 2.0
   end do
   
   !display the values
   do i = 1, 5
      Print *, numbers(i)
   end do
   
   !assigning some values to the array matrix
   do i=1,3
      do j = 1, 3
         matrix(i, j) = i+j
      end do
   end do
   
   !display the values
   do i=1,3
      do j = 1, 3
         write(*,*) matrix(i,j)
      end do
   end do
   
   !short hand assignment
   numbers = (/1.5, 3.2,4.5,0.9,7.2 /)
   
   !display the values
   do i = 1, 5
      write(*,*) numbers(i)
   end do
   
end program arrayProg
Posted by: Guest on April-07-2020
0

arrays in fortran

program arraySubsection

   real, dimension(10,10) :: a, b
   integer:: i, asize, bsize
   
   a(-3,1:7) = 5.0 ! a(1) to a(7) assigned 5.0
   a(-1,8:) = 0.0  ! rest are 0.0 
   b(2:10:2) = 3.9
   b(1:9:2) = 2.5
   
   !display
   asize = size(a)
   bsize = size(b)
   
   do i = 1, asize
      Print *, a(i,i)
   end do
   
   do i = 1, bsize
      Print *, b(i)
   end do
   
end program arraySubsection
Posted by: Guest on August-31-2021

Browse Popular Code Answers by Language