Professional Documents
Culture Documents
Lec 1b PDF
Lec 1b PDF
Pallab Dasgupta
Professor, Dept. of Computer Sc. & Engg.,
Indian Institute of Technology Kharagpur
Algorithm / Flowchart
A step-
step-by
by--step procedure for solving a particular problem.
Independent of the programming language.
Program
A translation of the algorithm/flowchart into a form that can be
processed by a computer.
Typically written in a high-
high-level language like C, C++, Java, etc.
Address 0
Address 1
Address 2
Address 3
Every variable is
Address 4
mapped to a particular
Address 5
memory address
Address 6
Address N-1
X = 10 10
T
i X = 20 20
m
e
X=X+1 21
X=X*5 105
Variable
Instruction executed
X Y
X = 20 20 ?
T
i Y = 15 20 15
m
e
X=Y+3 18 15
Y=X/6 18 3
Floating
Floating--point :: can store numbers with fractional values.
Examples: 3.14159, 5.0, -12345.345
Step 1:
Clearly specify the problem to be solved.
Step 2:
Draw flowchart or write algorithm.
Step 3:
Convert flowchart (algorithm) into program code.
Step 4:
Compile the program into object code.
Step 5:
Execute the program.
Computation
Input / Output
Decision Box
Start / Stop
Flow of
control
Connector
START
READ A, B, C
S=A+B+C
OUTPUT S
STOP
START
READ X, Y
YES IS NO
X>Y?
OUTPUT X OUTPUT Y
STOP STOP
START
READ X, Y, Z
YES IS NO
X > Y?
Max = X Max = Y
YES IS NO
Max > Z?
OUTPUT Max OUTPUT Z
STOP STOP
START
READ N
SUM = 0
COUNT = 1
COUNT = COUNT + 1
NO IS YES
COUNT > N? OUTPUT SUM
STOP
START
READ N
SUM = 0
COUNT = 1
COUNT = COUNT + 1
NO IS YES
COUNT > N? OUTPUT SUM
STOP
START
READ N
SUM = 0
COUNT = 1
COUNT = COUNT + 1
NO IS YES
COUNT > N? OUTPUT SUM
STOP
START
READ N
PROD = 1
COUNT = 1
COUNT = COUNT + 1
NO IS YES
COUNT > N? OUTPUT PROD
STOP
START
READ X, N
TERM = 1
SUM = 0
COUNT = 1
COUNT = COUNT + 1
NO IS YES
COUNT > N? OUTPUT SUM
STOP
START
READ X, N
TERM = 1
SUM = 0
COUNT = 1
COUNT = COUNT + 1
NO IS YES
TERM < 0.0001? OUTPUT SUM
STOP
ax2 + bx + c = 0
TRY YOURSELF
MARKS 90 Ex
89 MARKS 80 A
79 MARKS 70 B
69 MARKS 60 C
59 MARKS 50 D
49 MARKS 35 P
34 MARKS F
START
READ MARKS
NO NO NO
MARKS 90? MARKS 80? MARKS 70? A
YES YES YES