- Fortran Tutorial
- Fortran - Home
- Fortran - Overview
- Fortran - Environment Setup
- Fortran - Basic Syntax
- Fortran - Data Types
- Fortran - Variables
- Fortran - Constants
- Fortran - Operators
- Fortran - Decisions
- Fortran - Loops
- Fortran - Numbers
- Fortran - Characters
- Fortran - Strings
- Fortran - Arrays
- Fortran - Dynamic Arrays
- Fortran - Derived Data Types
- Fortran - Pointers
- Fortran - Basic Input Output
- Fortran - File Input Output
- Fortran - Procedures
- Fortran - Modules
- Fortran - Intrinsic Functions
- Fortran - Numeric Precision
- Fortran - Program Libraries
- Fortran - Programming Style
- Fortran - Debugging Program
- Fortran Resources
- Fortran - Quick Guide
- Fortran - Useful Resources
- Fortran - Discussion
Fortran - Arithmetic Operators
Following table shows all the arithmetic operators supported by Fortran. Assume variable A holds 5 and variable B holds 3 then −
Operator | Description | Example |
---|---|---|
+ | Addition Operator, adds two operands. | A + B will give 8 |
- | Subtraction Operator, subtracts second operand from the first. | A - B will give 2 |
* | Multiplication Operator, multiplies both operands. | A * B will give 15 |
/ | Division Operator, divides numerator by de-numerator. | A / B will give 1 |
** | Exponentiation Operator, raises one operand to the power of the other. | A ** B will give 125 |
Example
Try the following example to understand all the arithmetic operators available in Fortran −
program arithmeticOp ! this program performs arithmetic calculation implicit none ! variable declaration integer :: a, b, c ! assigning values a = 5 b = 3 ! Exponentiation c = a ** b ! output print *, "c = ", c ! Multiplication c = a * b ! output print *, "c = ", c ! Division c = a / b ! output print *, "c = ", c ! Addition c = a + b ! output print *, "c = ", c ! Subtraction c = a - b ! output print *, "c = ", c end program arithmeticOp
When you compile and execute the above program, it produces the following result −
c = 125 c = 15 c = 1 c = 8 c = 2
fortran_operators.htm
Advertisements