0% found this document useful (0 votes)
16 views5 pages

Fortran Lesson 2

Uploaded by

kumarroy07203010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views5 pages

Fortran Lesson 2

Uploaded by

kumarroy07203010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

FORTRAN

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.

 Character type – The character type stores characters and strings.

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.

Syntax for variable declaration is as follows −


type-specifier :: variable_name

Every variable should be defined in a declaration. This establishes the type of the variable.
The most common declarations are:

integer list of variables


real list of variables
complex list of variables
logical list of variables
character list of variables
How does parameter Statement work?

The syntax of the parameter statement is,

parameter (name = constant, ... , name = constant)

The rules for the parameter statement are:


 The name defined in the parameter statement is not a variable but rather a constant.
 A name can appear in at most one parameter statement.
 The parameter statement(s) must come before the first executable statement.

program circle

real r, area, pi

parameter (pi = 3.14)

write (*,*) 'Give radius r:'

read (*,*) r

area = pi*r*r

write (*,*) 'Area = ', area , 'sq. unit'

end program circle


Logical Expression:

Logical expressions can only have the value .TRUE. or .FALSE..

.LT. meaning <


.LE. <=
.GT. >
.GE. >=
.EQ. =
.NE. /=

if Statement:
if (logical expression) then
statements
endif

Write a FORTRAN program to find the MAX between two


numbers.

program ex6

integer a,b
write (*,*) 'Enter two integer number : '
read (*,*) a, b
if (a .GT. b) then
write (*,*) a, ' is MAX'
endif

end program ex6


program ex7

integer a,b

write (*,*) 'Enter two integer number : '

read (*,*) a, b

if (a .GT. b) then

write (*,*) a, ' is MAX'

else

write (*,*) b, ' is MAX'

endif

end program ex7

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

write (*,*) 'Enter any integer number : '

read (*,*) n

if (Mod(n,2) .EQ. 0) then

write (*,*) n, ' is EVEN'

else

write (*,*) n, ' is ODD'

endif

end program ex8

You might also like