Professional Documents
Culture Documents
Ship Design-I
Lecture-4
DR. MD. MASHUD KARIM
DR. ZOBAIR IBN AWAL
MD. HABIBUR RAHMAN
MD. MOINUL ISLAM
09/21/2020 1
Student learning is less effective when students sit
inertly in classes barely listening to teachers, passively
viewing PowerPoint presentations, memorizing pre-
packaged assignments, and spitting out answers.
Learning is not a spectator sport. Student learning is
optimized when students are actively involved in
their own learning. Students must talk about what
they are learning, write about it, relate it to past
experience, and apply it in their own lives. They must
make what they learn part of themselves.
Adapted from Chickering and Gamson, Seven
Principles for Good Practice in Undergraduate
Education
09/21/2020 2
Transfer of Control
The computer normally executes the instructions of a Fortran program
one line after another unless it is instructed otherwise. The order of
execution can be controlled by various instructions. Basically, there are
two types of transfer of control: unconditional and conditional.
Unconditional Transfer
09/21/2020 3
Write a Fortran Program that generates and prints the
positive numbers.
Start
I =1
99 Print*, I
I = I+1
I 1 Goto 99
End
I =1
Print I 99 Write (6, 20) I
20
Format (1X, I4)
I = I+1
Goto 99
I I +1 End
09/21/2020 4
Start
SUM S1 + S2+ S3
AVE SUM/3
Write AVE
09/21/2020 5
Sample Program with Goto
Program average
100 Read*, id, s1, s2, s3
Print*, id, s1, s2, s3
sum = s1 + s2 + s3
ave = sum/3.0
Print*, “The average is:” ave
Goto 100
Stop
End
09/21/2020 6
Logical IF Statement
IF (Logical Expression) Statement A
Examples
IF (A.LE.B) GOTO 50 true
Logical
IF (L.GE.75) N = N+1
Exp.
IF (J.NE.K) Write(6,30) X, Y
false A
09/21/2020 7
Controlling a Loop
• Suppose we want to repeat a process (i.e., a set of
instructions) say 100 times.
09/21/2020 8
Start
I 1
Process
I I+1
yes
I<=100
no
09/21/2020 Stop 9
Conditional Transfer
If we want to generate only
first one hundred positive I 1
integers, i.e., we want the
program to terminate after
Print I
generating the integer 100.
I I +1
yes
I <= 100
no
Stop
09/21/2020 10
Class Exercise -1
Suppose an amount of 3000.00 Tk is deposited in a
savings account in year 2000, and suppose the bank pays
6.5 percent interest on the account compounded
annually. Write a program which prints the YEAR and the
Amount of the account until 2020.
Clue:
Each year, AMOUNT is increased by 6.5 percent. Thus the
assignment,
AMOUNT <- AMOUNT + 0.06*AMOUNT
Is repeated as long as YEAR <- 2020.
09/21/2020 11
YEAR <- 2000
AMOUNT <- 3000.00
Print
YEAR,
AMOUNT
yes
YEAR <- 2020
no
Stop
09/21/2020 12
Class Exercise -2
09/21/2020 13
Class Exercise -3
09/21/2020 14