Lecture 3
Lecture 3
Problem: Write an algorithm to calculate the sum of first seventy natural numbers.
Solution:
1 Start
2 Sum = 0
3 Num = 0
4 Repeat Step 5 and 6 until (Num < = 70)
5 Sum = Sum + Num
6 Num = Num + 1
7 Display Sum
8 End
Example: Daily Life problems
Reduced Complexity
Increased Flexibility
Ease of Understanding
flow
chart
Start
Enter number1
Enter number2
Display Result
End
Example: Calculate distance covered by a car moving at an
average speed of V m/s in time T
Start
Input velocity
Input time
Distance = velocity*time
Display Distance
End
Example: Calculate the sum of first seventy natural numbers
Start
Sum = 0
Num = 0
Num = Num +1
NO
IS Num = 70?
YES
Display Sum
End
Algorithm vs Flowchart
Algorithm Flowchart
Simple English is used to write algorithm Standard Symbols are used to design flowchart
Step by step procedure to solve a problem Graphical representation of solution
Less time consuming More time consuming
Easy to modify Difficult to modify
Example: Daily Life problems
If any of these six steps are not completed well, the results may be less than desired.
1. Problem
Design an algorithm
Stepwise Refinement
Development of a detailed list of steps to solve a particular step in the original algorithm
4. Implementation
Convert each algorithm step into one or more statements in a programming language.
5.Testing
Detection of errors in the software by providing different values as input and then check
the output.
6. Maintenance
Gary j. Bronson, A first book of C++, Garry Bronson, 4th edition (Section 1.1 of Chapter 1)
Maureen Sprankle et al, Problem Solving and Programming Concepts, 9 th Ed. Prentice Hall,
2011. (Chapter 1 + All the related topics of Flowchart and algorithms in book)