Skip to main content

9.1) Functions


If you are planning on using a certain calculation over and over again then you should make it a function. For instance, say in your program you need to use the sin(x) function and you plan on using it several times. You don’t want to have to write out the code to do the calculation over and over again. You just want to be able to call up a function that does that calculation.

What you want is a function such that given x it returns a value for sin(x). So x is the input and the function would output the value of sin(x). For commonly used functions, Fortran has already written the code for you and made it accessible. So functions like sin(x), cos(x), log(x), etc are all readily available. These are called intrinsic functions because you don’t have to write the code, it is already written for you. The following table lists some common intrinsic functions that are used but there are many more.