Problem Solving�
To solve a problem using computer, there are certain activities to be planned which include:
Activities
Specify the problem statement: We can solve a problem only if it is known what is to be done. The specification of the problem statement involves the following:
Activities
Problem Solving Techniques�
Flowchart
Algorithm and
Pseudo code.
Flowchart �
Flowchart symbols
Flowchart symbols
Flowchart symbols and its purpose�
Guidelines for preparing flowcharts�
Guidelines for preparing flowcharts
Benefits of flowcharts �
Limitations of flowchart�
TECHNIQUES
Flowchart to find sum of two numbers�
�Flowchart to find sum and average of three numbers�
Flowchart to find the area of a rectangle�
Flowchart to convert temperature from Celsius to Fahrenheit
Flowchart to convert inches to centimetres
Flowcharts for decision making ( Pass/Fail) �
Flowchart to find maximum of three numbers�
�Calculating Cutoff mark for ‘N’ students�
Algorithm�
Real Life Example
Algorithm to prepare a coffee
Step 1: Start
Step 2: Get the ingredients WATER, MILK, SUGAR and COFFEE POWDER
Step 3: Boil the WATER and add COFFEE POWDER
Step 4 : Add SUGAR and pour MILK
Step 5: Stir well
Step 6: Pour into cup
Step 7: A CUP OF COFFEE is ready to drink
Step 8 : Stop
Algorithm
To find total and average of three numbers
Step 1 : Start
Step 2 : Read the numbers, say A, B and C
Step 3 : Add A, B and C and store it in SUM
Step 4: Divide the SUM by 3 and store it in AVERAGE
Step 4 : Display the SUM, AVERAGE
Step 5 : Stop
Algorithm to find area of a rectangle�
Step 1: Start
Step 2: Read the LENGTH and BREADTH of the rectangle
Step 3: Multiply LENGTH and BREADTH to compute the AREA
Step 4: Display the AREA
Step 5: Stop
Algorithm to find maximum of three numbers�
Step 1 : Start
Step 2 : Read the three numbers, say A, B and C
Step 3 : Check whether A is greater than B and C. If, so display A is biggest
number and Stop
Step 4 : Otherwise, check whether B is greater than C. If, so display B is the
biggest number and stop.
Step 5 : Otherwise, display C is the biggest number
Step 6 : Stop
Calculating cutoff mark for N students
Step 1 : Start
Step 2: Read the number of students
Step 3: Initialize the COUNT to 1
Step 4: Initialize the CUTOFF to 0
Step 5 : If COUNT is less than or equal to N, Read MATHS, PHYSICS and
CHEMISTRY marks of a student. Otherwise go to Step 10
Step 6: Calculate CUTOFF by dividing the MATHS mark by 2, PHYSICS
and CHEMISTRY marks by 4 and adding them together (i.e)
CUTOFF = MATHS/2+PHYSICS/4+CHEMISTRY/4
Step 7: Increment the COUNT by 1
Step 8: Display the CUTOFF
Step 9: Go to Step 4
Step 10: Stop
Properties of an Algorithm
�Advantages of Algorithms�
�Disadvantages of Algorithms�
Pseudocode
Guidelines for writing pseudocode�
Advantages of pseudo code�
Limitations of pseudo code�
Keywords�
Left side 🡨Right Side
Right side value is assigned to the left side variable.
Constructs
a. If-Then-Else �
If condition Then
sequence 1
Else
sequence 2
Endif
b. While �
While condition
sequence
Endwhile
c. Case �
Case expression of
condition 1 : sequence 1 � condition 2 : sequence 2 � ... � condition n : sequence n �Others: � default sequence
Endcase
d.Repeat-Until �
Repeat
sequence
Until condition
e.For �
For variable 🡨 start to end increment/ decrement by number
sequence
Endfor
�Pseudo code to find sum and �Average of Three Numbers�
Begin
Get A,B,C
SUM 🡨 A + B + C
AVERAGE🡨SUM/3
Display SUM
End
��Pseudo code to find maximum of three numbers��
Begin
Get A, B and C
If A > B and A > C then display A
Else If B > C then display B
Else Display C
Endif
Endif
End
Calculating cutoff mark for N students�
Begin
Get N
For COUNT🡨1 to N
Read MATHS, PHYSICS, CHEMISTRY
CUTOFF 🡨 MATHS/2+PHYSICS/4+CHEMISTRY/4
Display CUTOFF
Endfor
End
Pseudo code to find sum till -1 is entered�
Begin
SUM 🡨 0
Repeat
Get A
If A < > -1 then
SUM 🡨SUM+A
Endif
Until A = = -1
Display SUM
End
�Exchanging the values of two variables�
Algorithm
Step 1: Start
Step 2: Read two numbers, say FIRST and SECOND
Step 3: Move the value of FIRST to T
Step 4: Move the value of SECOND to FIRST
Step 5: Move the value of T to SECOND
Step 6: Display the value of FIRST and SECOND
Step 7: Stop
Pseudocode �
Begin
Get FIRST, SECOND
T 🡨 FIRST
FIRST 🡨 FIRST
SECOND 🡨 T
Display FIRST, SECOND
End
Flowchart
Finding the biggest among N numbers�
Algorithm
Step 1 : Start
Step 2 : Read the number of elements among which maximum is to be found, say N
Step 3 : Initialize COUNT to 1
Step 4 : Read the first number, NUMBER and consider it as the BIGGEST
Step 5 : If COUNT is less than or equal to N, then read the next number, NUMBER
Otherwise go to Step 9.
Step 6: If NUMBER is greater than BIGGEST, the assign NUMBER to BIGGEST
Step 7 : Increment the COUNT by 1
Step 8: Go to Step 5
Step 9 : Display the BIGGEST
Step 10: Stop
Pseudocode �
Begin
Get N
COUNT 🡨 1
Get NUMBER
BIGGEST 🡨 NUMBER
For COUNT🡨 2 to N
Get NUMBER
If NUMBER > BIGGEST then
BIGGEST 🡨 NUMBER
Endif
Endfor
Display BIGGEST
End
Flow Chart
�Counting�
a. Algorithm
Step 1: Start
Step 2 : Read the number of students whose marks are to be counted as pass
or fail, say N
Step 3 : Initialize I to 1, PASS_COUNT and FAIL_COUNT to 0
Step 4 : Read the mark, say MARK
Step 5 : If MARK is greater than or equal to 50, then PASS_COUNT is
incremented Otherwise, FAIL_COUNT is incremented
Step 6 : Increment I by 1
Step 7 : If I is less than or equal to N, go to step 4
Step 8 : Display the PASS_COUNT and FAIL_COUNT
Step 9 : Stop
Pseudocode�
Begin
Get N
PASS_COUNT 🡨0
FAIL_COUNT 🡨0
For I 🡨 1 to N
Get MARK
If MARK > = 50 then
PASS_COUNT 🡨 PASS_COUNT + 1
Else
FAIL_COUNT 🡨 FAIL_COUNT + 1
Endif
Endfor
Display PASS_COUNT, FAIL_COUNT
End
Flowchart
�Summation of ‘n’ numbers�
a. Algorithm
Step 1: Start
Step 2: Read the number upto which sum is to be found, say N
Step 3: Initialize the COUNT to 1 and SUM to 0
Step 4: Read the number to be added, say A
Step 5: Add A to SUM
Step 6: Increment COUNT by 1
Step 7: If the value of COUNT is greater than N, then goto Step 9
Step 8:otherwise Goto Step 4
Step 9: Display the value of SUM
Step 10: Stop
Pseudocode�
Begin
Get N
COUNT 🡨 1
SUM 🡨 0
For COUNT 🡨 1 to N
Get A
SUM🡨SUM+A
Endfor
Display SUM
Stop
Flowchart
Finding the factorial of a given number �
Algorithm:
Step 1: Start
Step 2: Initialize I to 1 and FACT to 1
Step 3: Read the number to find factorial,say , N
Step 4: Multiply FACT and I and store the result in FACT
Step 5: Increment I by 1
Step 6 : If I is greater than N then goto step 8
Step 7: Goto Step 4
Step 8: Display the value of FACT
Step 9: Stop
Pseudocode
Begin
Get N
FACT 🡨 1
For I 🡨 1 to N
FACT 🡨 FACT * I
Endfor
Display FACT
End
Flowchart
Generation of Fibonacci series�
0, 1 , 1, 2, 3, 5, 8, 13,. . .
From the Fibonacci sequence, we know that
New term = previous term + term before previous term
Let us define
FIB as the new term
K as the preceding term of FIB
J as the term before the preceding term of k
The initial values are:
J 🡨 0 First Fibonacci number
K 🡨1 Second Fibonacci number
FIB 🡨 J+K Third Fibonacci number
Algorithm
Step 1: Start
Step 2: Initialize I, J and FIB to 0 and K to 1
Step 3: Read the number upto which the Fibonacci series to be
generated, say N
Step 4: Display the FIB
Step 5 : Assign K to J and FIB to K
Step 6: Add J and K and store it in FIB
Step 7 : Increment I by 1
Step 8: If I is less than N goto Step 4
Step 9: Stop
Pseudocode�
Begin
I 🡨 0, FIB 🡨 0, J 🡨 0, K 🡨1
Get N
For I 🡨 1 to N
Display FIB
J 🡨 K
K 🡨 FIB
FIB 🡨 J+K
Endfor
End
Flowchart
Reversing the digits of an integer�
Step 1: Start
Step 2: Read the number whose reverse is to be found, say N
Step 3: Initialize REVERSE to 0
Step 4 : Divide N by 10 and store the reminder in REM
Step 5: Multiply the REVERSE by 10 and add the REM to it
Step 6 : Divide N by 10 and store the quotient in N
Step 8: If N is greater than 0, the goto Step 4
Step 9: Display the reverse number, REVERSE
Step 10: Stop
Reversing the digits of an integer
Pseudocode�
Begin
Get N
REVERSE 🡨 0
Repeat
REM 🡨 N % 10
REVERSE 🡨 REVERSE * 10 + REM
N 🡨 N/10
Until N = 0
Display REVERSE
End