Fortran Lesson 2
Fortran Lesson 2
Data type:
FORTRAN provides five intrinsic data types:
Integer type – The integer types can hold only integer values.
Real type – It stores the floating point numbers, such as 2.0, 3.1415, -100.876, etc.
Complex type – This is used for storing complex numbers. A complex number has two parts,
the real part and the imaginary part. Two consecutive numeric storage units store these two
parts. For example, the complex number (3.0, -5.0) is equal to 3.0 – 5.0i.
Logical type – There are only two logical values: .true. and .false.
What is Variable?
A variable is a name given to a storage area that the programs can manipulate. Each variable
should have a specific type, which determines the size and layout of the variable’s memory.
Every variable should be defined in a declaration. This establishes the type of the variable.
The most common declarations are:
program circle
real r, area, pi
read (*,*) r
area = pi*r*r
if Statement:
if (logical expression) then
statements
endif
program ex6
integer a,b
write (*,*) 'Enter two integer number : '
read (*,*) a, b
if (a .GT. b) then
write (*,*) a, ' is MAX'
endif
integer a,b
read (*,*) a, b
if (a .GT. b) then
else
endif
if..else Statement:
if (logical expression) then
statements
else
statements
endif
Write a FORTRAN program to check whether a given number
is odd or even.
program ex8
integer n
read (*,*) n
else
endif