CH - 4 Intro To Problem Solving
CH - 4 Intro To Problem Solving
Algorithm
A set of exact steps which when followed, solve the problem or accomplish the required task or it is a
step by step procedure to perform an operation which will lead to the desired result, if followed correctly.
Pseudocode
➢ It is another way of representing an algorithm.
➢ It is considered as an non formal language that helps programmer to write algorithm.
Q3. Write pseudocode and draw a flowchart to accept 5 numbers and find their average.
Pseudocode will be as follows: Flowchart:
Step 1: SET count = 0, sum = 0
Step 2: WHILE count <5 , REPEAT steps 3 to 5
Step 3: INPUT a number to num
Step 4: sum = sum + num
Step 5: count = count + 1
Step 6: COMPUTE average = sum/5
Step 7: PRINT average
Flow of Control
The flow of control depicts flow of events as represented in flow chart.
The events can flow in any of the following ways:
1. Sequences:
An Algorithm where all steps are executed one after the other are said to be execute in sequence.
Eg> refer Q 1
2. Selection:
Any one of the alternative is selected based on outcomes of a condition .
Conditionals are used to check possibilities.
The program checks one or more conditions and perform operations depending on True or False
value of condition.
Note : In programming languages True or False conditions are written using if-else block in actual
program.
“Otherwise” is used as ‘Else keyword’. Eg. Flowchart Q3
3. Repetition( Loop Iteration):
In programming repetition is known as loop or iteration.
A loop in an algorithm means execution of some algorithm statements repeatedly until some
specified condition is satisfied. Eg. Q 3
Decomposition
The basic idea of solving a problem by decomposition is to decompose or breakdown a complex
problem into smallest subproblem.
***************************