fork download
  1. program sliceArray
  2. integer, dimension(10,10) :: theArray
  3. integer :: i, j
  4.  
  5. theArray = 0
  6. theArray(3:7,3:7) = 1
  7.  
  8. do i = 3,7
  9. do j = 3,7
  10. theArray(i,j) = j
  11. end do
  12. end do
  13.  
  14.  
  15. do i = 1,10
  16. do j = 1,10
  17. write(*,"(I2)",advance="no") theArray(i,j)
  18. end do
  19. write(*,*)
  20. end do
  21. print *, theArray(:, 4) ! fourth column
  22. print *, theArray(7, :) ! seventh row
  23. print *, theArray(:7, 3:7)
  24. print *, theArray((/3,4,5/), :)
  25. end
  26.  
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
 0 0 3 4 5 6 7 0 0 0
 0 0 3 4 5 6 7 0 0 0
 0 0 3 4 5 6 7 0 0 0
 0 0 3 4 5 6 7 0 0 0
 0 0 3 4 5 6 7 0 0 0
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
           0           0           4           4           4           4           4           0           0           0
           0           0           3           4           5           6           7           0           0           0
           0           0           3           3           3           3           3           0           0           4           4           4           4           4           0           0           5           5           5           5           5           0           0           6           6           6           6           6           0           0           7           7           7           7           7
           0           0           0           0           0           0           3           3           3           4           4           4           5           5           5           6           6           6           7           7           7           0           0           0           0           0           0           0           0           0