FORTRAN was the first programming language, developed by John W. Backus in 1957. There are six basic data types in FORTRAN:
These data types are further categorized into two types.
Integer
Integers are the discrete and exact numbers; they range from -2x10^9 to 2x10^9 on a 32-bit machine. Integers can have an optional sign in them. The basic operations that can be performed on integers are addition, subtraction, multiplication, division, and exponentiation.
Examples of integers are 3, 0, 25, -6, etc.
# Declare integerinteger :: number# Assign value to integernumber = 4000# Print number (On execution, it will print: 4000)Print *, number
Real
The real
data type represents the real numbers that are used to measure quantities. Real numbers have a mandatory decimal point and an optional sign in them.
They range from -10^77 to 10^77. Just like integers, we can perform addition, subtraction, multiplication, division, and exponentiation on real numbers too.
Some examples of real numbers are 0.3, 7.08, 6.02x10E23, etc.
# Declare real numberreal :: div# Assign value to real numberdiv = 147.47# Print div (On execution, it will print: 147.470001)Print *, div
Complex
The complex
data type stores complex numbers that have a real and imaginary part.
For example, the complex number
4.0-7.0i is represented as (4.0, -7.0)
in FORTRAN.
# Declare complex numbercomplex :: complexValue# Assign value to complex numbercomplexValue = (2.0, 5.0)# Print complexValue (On execution, it will print: (2.00000000,5.00000000))Print *, complexValue
Double precision
The double precision
data type is similar to real numbers, but has greater precision. It has an accuracy of up to 14 digits. The same mathematical operations of integers and real numbers can be performed on the double precision
data type.
Some examples include 1.3D+2
, 1D-02
, etc. Here, D
represents the exponent, as E
does in real numbers.
# Declare double precision numberdouble precision :: dub# Assign value to double precision numberdub = 7777.77777# Print dub (On execution, it will print: 7777.7778320312500)Print *, dub
Character
The character
data type shows
Some examples are: ‘Welcome to Educative’, ‘1234A7’, etc. To show a single quote in character
data type, two single quotes are placed together, e.g, ‘Educative’’s courses’
will be printed as Educative’s courses
.
# Declare charactercharacter(len=40) :: welcomeMessage# Assign value to characterwelcomeMessage = "Welcome to educative"# Print welcomeMessage (On execution, it will print: Welcome to educative)Print *, welcomeMessage
Logical
The logical
data type shows two possible states, true
and false
only. Logical AND
, OR
, and NOT
operations can result in this data type.
# Declare logicallogical :: check# Assign value to logicalcheck = .true.# Print check (On execution, it will print: T)Print *, check