In FORTRAN, addition and subtraction are denoted by the usual plus (+) and minus (-) signs. Multiplication is denoted by an asterisk (*). This symbol must be used to denote every multiplication; thus to multiply **N** by 2, we must use **2 * N** or **N * 2** not **2N**. Division is denoted by a slash (/), and exponentiation is denoted by a pair of asterisks (**).

Operator | Operation |

+ | addition, unary plus |

- | subtraction, unary minus |

* | multiplication |

/ | division |

** | exponentiation |

Providing all variables and constants in the expression are real, real arithmetic will be carried out as expected, with no decimal places being truncated.

Providing the expression has all integers, subtraction, addition, multiplication and exponentiation will prove no problem. However integer division is somewhat different than normal division with real values. Integer division ignores the fractional part. Any decimal places are truncated.

Example

5 / 2 gives the result 2 instead of 2.53 / 4 gives the result 0 instead of 0.75

Mixed mode arithmetic is when an expression contains both reals and integers. If ANY of the operands are real then result of the operation will be real. However, mixed mode arithmetic should be used with extreme care. You may think you have a real operand when in reality you have two integer operands.

Example

5 / 2 * 3.0 | is 6.0 Incorrect because the order of operation is left to right. 5/2 = 2 then 2 * 3.0 = 6.0 |

3.0 * 5 / 2 | is 7.5 Correct because of mixed mode arithmetic 3.0 * 5 = 15.0 then 15.0/2 = 7.5 |

If the variable to which an expression is assigned has been declared as a real variable, any decimal places resulting from the evaluation of the expression will be preserved.

Example

real variable 5 * 2.1 will have a value of 10.5.

However, if the variable to which an expression is assigned has been declared as an integer variable, any decimal places resulting from the evaluation of the expression will be lost.

Example

integer variable 5 * 2.1 will have a value of 10- All exponentiations are performed first; consecutive exponentiations are performed from right to left.
- All multiplication and divisions are performed next, in the order in which they appear from left to right.
- The additions and subtractions are performed last, in the order in which they appear from left to right.

funtionname (name1, name2,.......) |

Function | Description | Type of Argument(s)* | Type of Value |
---|---|---|---|

ABS (x) | Absolute value of x | I, R, DP | Same as argument |

COS (x) | Cosine of x radians | R, DP | Same as argument |

DBLE(x) | Conversion of x to double precision form | I, R | DP |

DPROD(x,y) | Double precision product of x and y | R | DP |

EXP(x) | Exponential function | R, DP | Same as argument |

INT(x) | Integer part of x | R, DP | I |

LOG(x) | Natural logarithm of x | R, DP | Same as argument |

MAX(xl, . . . , Xn) | Maximum of xl, . . .,xn | I, R, DP | Same as argument |

MIN(xl, . . . , xn) | Minimum of xl, . . ., xn | I, R, DP | Same as argument |

MOD(x,y) | x (mod y); x - INT(x/y) * y | I, R, DP | Same as argument |

NINT(x) | x rounded to nearest integer | R, DP | I |

REAL(x) | Conversion of x to real type | I, DP | R |

SIN(x) | Sine of x radians | R, DP | Same as argument |

SQRT(x) | Square root of x | R, DP | Same as argument |

* I = integer, R = real, DP = double precision.

variable = expression |

For Example:

Work your way through the following components attempting the exercises as you come across them: | Programs | Variables | Arithmetic Operations | Input and Output | Looping in Programs | Arrays in Programs | Checking variables | Subprograms and functions | |