Categories: ## 1. Arithmetic Operations

Arithmetic operations are denoted by following arithmetic operators:

• Subtraction –
• Multiplication *
• Division /
• Exponentiation **

## Order of Precedence

Operands of an arithmetic operation may be a numeric constant, numeric variable or an arithmetic expression in parentheses. Two operators cannot be written consecutively. Operations must be defined in a particular sequence as is done in a simple mathematics using BODMAS rule. But here the rules are slightly different from standard BODMAS.

Evaluation begins with the leftmost operand and follow the trend:

• **
• * /
• + –

such that operators in the same line have equal precedence and precedence decreases downwards. A parenthesized expression is evaluated first than others. Exponentiation is performed from the right to left to in contrast to other operators that are applied from left to right.

Example 1: 2**3**3 = 2*27 = 134,217,728

Example 2: 9/5*100 = 1*100 = 100

## Type Rules

Broadly, three rules are worth considering here for application of arithmetic operators. Firstly, if both the operands are of same type. i.e both are of type REAL or both are INTEGER, then the result is also REAL or INTEGER respectively. Secondly, when a INTEGER operates upon another INTEGER, result may be a REAL for example while computing 7/5, we get 1.4. In such a case, FORTRAN truncates the answer to the corresponding INTEGER value and thus result in the above case is 1. Lastly, If one operator is INTEGER and other is REAL, firstly convert the INTEGER to its REAL equivalent and then compute the result. This way result obtained is of type REAL.

## Arithmetic Assignment

numeric_variable= arithmetic expression

Example:

```REAL   A B C
A  =  B+C```

## 2. Logical Operations

Logical operations use following operators:

• Both A and B are true – .AND
• Either A or B is true – .OR
• A is not true – .NOT
• If A is true/false, B is also true/false – .EQV
• If A is true, B is false or vice versa – .NEQV

where A and B are logical expressions and the syntax for the operation is

`Logical Expression (A) _Logical operator_Logical Expression (B)`

## Logical Expressions

Syntax for a logical expression is

`Arithmetic Expression _ Relational Operator _ Arithmetic Expression`

There are several Relational Operators:

• Less Than – .LT.
• Less Than or equal to – .LE.
• Greater Than- .GT.
• Greater Than or Equal To – .GE.
• Equal to – .EQ.
• Not Equal To- .NE.

## Logical Assignment

```LOGICAL VALID
VALID= X.GT.MIN .AND. X.LT.MAX```

This means Answer is VALID when X is greater than MIN and less than MAX.

Today's Hot Deal ## Order of Precedence

• Arithmetic Operators
• Relational Operators
• .NOT.
• .AND.
• .OR.
• .EQV. and .NEQV.

## 3. Character Operations

The only character operator is concatenation operator whose symbol is //. Here a//z means concatenate a with z. In a character operation , operands are of type character. They may be constant, variable, string, function or an array element. ``` ```

## Subscribe

* indicates required

Translate »