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

FORTRAN Lesson 3

Fortran class notes

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)
13 views5 pages

FORTRAN Lesson 3

Fortran class notes

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

if..elseif Statement:
if (logical expression) then
statements
elseif (logical expression) then
statements
:
:
else
statements
endif

! Find the Largest Number Among Three Numbers

program ex9
integer :: a, b, c
write (*,*) 'Enter three integer number:'
read (*,*) a, b, c
if ((a .GT. b) .AND. (a .GT. c)) then
write (*,*) a, ' is MAX'
elseif ((b .GT. c) .AND. (b .GT. a)) then
write (*,*) b, ' is MAX'
elseif ((c .GT. a) .AND. (c .GT. b)) then
write (*,*) c, ' is MAX'
else
write (*,*) 'Three numbers are equal'
endif
end program ex9
Nested-if Statement:
!Program to Check Leap Year

program ex10

integer :: yr

write (*,*) 'Enter a year:'

read (*,*) yr

if (Mod(yr,4) .EQ. 0) then

if (Mod(yr,100) .EQ. 0) then

if (Mod(yr,400) .EQ. 0) then

write (*,*) yr, ' is a leap year.'

else

write (*,*) yr, ' is not a leap year.'

endif

else

write (*,*) yr, ' is a leap year.'

endif

else

write (*,*) yr, ' is not a leap year.'

endif

end program ex10


Select Case Statement:
SELECT CASE (selector)
CASE (label-list-1)
statements-1
CASE (label-list-2)
statements-2
CASE (label-list-3)
statements-3
.............
CASE (label-list-n)
statements-n
CASE DEFAULT
statements-DEFAULT
END SELECT

!Program to perform basic task of a Calculator

program ex11

integer :: a, b, choice

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

read (*,*) a, b

write (*,*)'1. Addition'

write (*,*)'2. Sustraction'

write (*,*)'3. Multiplecation'

write (*,*)'4. Division'

write (*,*)'Enter your choice'

read (*,*) choice

select case (choice)

case (1)

write (*,*) 'Sum=',(a+b)

case (2)
write (*,*) 'Difference=',(a-b)

case (3)

write (*,*) 'Product=',(a*b)

case (4)

write (*,*) 'Quotient=',(a/b)

write (*,*) 'Remainder=',Mod(a,b)

case default

write (*,*) 'Wrong choice. You should enter within 1-4.'

end select

end program ex11

You might also like