![]() ![]() ![]() Subroutine square_cube ( i, isquare, icube ) integer, intent ( in ) :: i ! input integer, intent ( out ) :: isquare, icube ! output isquare = i ** 2 icube = i ** 3 end subroutine program main implicit none external square_cube ! external subroutine integer :: isq, icub call square_cube ( 4, isq, icub ) print *, "i,i^2,i^3=", 4, isq, icub end program Intent The following program calls a function to compute the sum of the square and the cube of an integer. In Fortran, one can use a function to return a value or an array of values. A subroutine does not return a value, but can return many values via its arguments and can only be used as a stand-alone command (using the keyword call). A function must return a single value, and can be invoked from within expressions, like a write statement, inside an if declaration if (function) then, etc. Haskell) only allow functions, because subroutines can, in some case, modify input variables as side-effects, which can complicate the code.įunctions are simpler than subroutines. Pure functional programming languages (e.g. ![]() Many programming languages do not distinguish between functions and subroutines (e.g. call sub1 ( e, f ) ! Now e or f, or both (or neither) may be modified. ! sub1 performs some operation on input variables e and f. ! sub1 is a subroutine defined elsewhere. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |