Program Development Styles and Basics of C 15
In addition, the flowchart has two more symbols to indicate the beginning and the end of the program
as per Fig. 1.19. The standard terminator symbol is racetrack.
Begin
I
Accept
number
x
Calculate square
of the number
Display
number
End
Begin
1) Accept number
2) Calculate square of
the number
3) Display number
-End
Fig. 1.19 Pseudocode and flowchart of a program
1.8 SEQUENCE AND SELECTION
The steps in an algorithm can be divided into three categories.
1) Sequence: The steps described in the algorithm are performed successively one by one without
skipping any step. The sequence of steps defined in the algorithm should be simple and easy to
understand. Each instruction of such an algorithm is executed, because no selection procedure or
conditional branching exists in a sequence algorithm. Fig. 1.20 represents the sequence of steps for a
telephonic conversation.
Consider an example described in the topic 'Algorithm'.
1) Dial the phone number
2) Phone rings at the called party
3) Caller waits for the response
4) Called party picks up the phone
5) Conversation begins between them
6) Release of connection
16 Programming and Data Structures
Fig. 1.20 Sequence algorithm
The above is a sequence algorithm and all the above six instructions are followed by the system. In
case some problem occurs, for example, after step 1, after dialing if the line is busy, there is no
alternative operation defined in the sequence to either exit or redial. In such a case, remaining
instructions will not be followed. This problem can be overcome by using selection method.
2) Selection: We understood that the algorithms written in sequence fashion are not reliable. There
must be a procedure to handle operation failure occurring during execution. The selection statements
can be as shown in Fig. 1.21.
If (condition)
Statement 1;
Else
Statement 2;
Fig. 1.21 Selection statements
In case the operation is unsuccessful, the sequence of algorithm should be changed/corrected in
such a way that the system will re-execute until the operation is successful. The above sequence of
algorithm can be modified as follows so that the system responds.
1) Dial the phone number
If (busy tone)
Goto step 1
2) Phone rings at the called party
3) Caller waits for the response
4) Called party picks up the phone
Program Development Styles and Basics of C 17
5) Conversation begins between them
6) Release of connection
Fig. 1.22 Selection algorithm
As given in Fig. 1.22 the selection block handles the situation and run-time failures can be avoided.
For a single problem, there may be multiple solutions. In such a situation, we have to apply multi
way (switch case) decision statements or we can extend two-way statements (example, if else) in a
ladder form.
Consider the following sequence of an algorithm.
1) Dial the phone number
If (busy tone)
Goto step 1
2) Phone rings at the called party
3) Caller waits for the response
4) Called party picks up the phone
5) Conversation begins between them
6) Release of connection
Suppose, at step 5 a message is voiced from called party such that 'dial extension code
.......
Assume extension code 21 for 'sales department/ 22 for 'accounts/ and so on.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.131.255