Fortran

Guide To Learn

Advanced Array Operations

This example shows how to use array operations and array slicing.

fortranCopy codeprogram advanced_array_operations
    implicit none
    integer, dimension(5) :: arr, sliced
    integer :: i

    ! Initialize array
    arr = (/1, 2, 3, 4, 5/)

    ! Array slicing
    sliced = arr(2:4)  ! Extract elements 2 to 4

    print *, 'Original array: ', arr
    print *, 'Sliced array: ', sliced

    ! Perform operations on the array
    arr = arr * 2  ! Double each element

    print *, 'Doubled array: ', arr
end program advanced_array_operations
Advanced Array Operations

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top