L3-L4 More On Algorithm
L3-L4 More On Algorithm
Introduction to algorithms
Objectives
Introduction to algorithms
2
Algorithm
3
Properties of an algorithm
4
Algorithmic Notations
• Name of the algorithm [mandatory]
[gives a meaningful name to the algorithm based on the
problem]
• Termination [mandatory]
[tells the end of algorithm]
5
Algorithm to compute the area of circle
Name of the algorithm : Compute the area of a circle
6
Algorithm to compute Simple and
Compound interest
Data:
P=amount deposited
T=duration
R=rate of interest
SI (P*R*T)/100
CI P*(1+ R/100)T -P
7
Simple and Compound interest
Name of the algorithm: Calculate SI and CI
15
Sum of digits of a number
Name of the algorithm: Find sum of the digits of a number
Step 1: [Read the number]
Input N
Step 2: [Set variable Sum equal to 0]
Sum0
Step 3: [Compute the sum of digits]
While N>0
begin
rem N mod 10
sum sum + rem
NN/10 (integer)
end
Properties of an algorithm
Algorithms for simple problems
19