@@ -49,17 +49,37 @@ program array_slice
49
49
50
50
integer :: i
51
51
integer :: array1(10) ! 1D integer array of 10 elements
52
+
52
53
integer :: array2(10, 10) ! 2D integer array of 100 elements
53
54
54
55
array1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ! Array constructor
55
- array1 = [(i, i = 1, 10)] ! Implied do loop constructor
56
+ print *, "Array at odd indices"
57
+ print *, array1(1:10:2) ! Print out elements at odd indices, start at element 1, go up to element 10, in strides of 2
58
+
59
+ print *, "Array in reverse!"
60
+ print *, array1(10:1:-1) ! Print an array in reverse
61
+
56
62
array1(:) = 0 ! Set all elements to zero
63
+ print *, "Reset array to 0!"
64
+ print *, array1
65
+
66
+ array1 = [(i, i = 1, 10)] ! Implied do loop constructor
67
+ print *, "Now back to 1 to 10!"
68
+ print *, array1
69
+
70
+
57
71
array1(1:5) = 1 ! Set first five elements to one
58
- array1(6:) = 1 ! Set all elements after five to one
72
+ print *, "Set first five elements to 1"
73
+ print *, array1
74
+
75
+ array1(6:) = 2 ! Set all elements after five to two
76
+ print *, "Set all elements after 5 to 2"
77
+ print *, array1
59
78
60
- print *, array1(1:10:2) ! Print out elements at odd indices
79
+
80
+ print *, "First column of 2d array"
61
81
print *, array2(:,1) ! Print out the first column in a 2D array
62
- print *, array1(10:1:-1) ! Print an array in reverse
82
+
63
83
64
84
end program array_slice
65
85
```
0 commit comments