Skip to main content

9.7) Make Your Own Functions (cont'd)


Here is an example of how to make your own functions. You add the code below a contains line.

       program example16
       real :: x,y,z
       x=5.0 ; y=10.0
       z=myfn(x,y)
       print *, z*z
       contains
       function myfn(x,y)
       real :: x,y,s,myfn
       s=(x**2+y**2)
       myfn=sqrt(s)
       end function myfn
       end program example16

An example of how to make your own code. The main driver code is above the ‘contains’ and the function is below the contains.