Problem Solving
Problem Solving
(5)
In your daily life, you may face a lot of problems through various activities that contain many
problems.
Problem is a situation that requires a solution or an objective you want to achieve through
following consecutive steps sequentially.
Problem Solving is the steps, activities, and processes to be done to reach an output or
objective.
Dear student
In this book, we focus on Problem Solving techniques
using the computer.
(6)
Flowchart:
It is a diagram that uses standard graphical symbols to illustrate the sequence of steps
required for solving a problem or specific question.
Some advantages of flowcharts:
Facilitating the reading and understanding of the problem and illustrating to the
programmer what must be done.
Useful to explain the program to others
helping in documenting the program in better manner, especially if the program is
complicated
Dear Student
After we have learnt about the problem-solving
stages and flowcharts, we will learn about some standard
(agreed on symbols), Special symbols can also be used for
exceptional cases.
Here are some of the most commonly used symbols as shown in table (1-1)
(7)
Significance symbol
)Terminal(
) Input/Output (
)Process(
)Decision(
)Flow Lines(
(8)
Second :Algorithm Third :Flowchart
1 Start
Start
2 Enter the number A and the
number B Enter A and B
End
1- The flowchart should start with the Start symbol and end with the End
symbol.
2- A,B,C are variable names .The variable refers to a memory storage that holds a
value.
3-The equation: C =A+B, indicates the sum of the value of A, to the value of B, and
stores the result in C.
4-Entering values in A and B is done by using the term “Enter”, inside a
parallelogram, you can also use another term to get the same meaning
like “Read” or “Input”.
(9)
First: Define the problem
Output: The value of “Y”.
Input: X.
Processing (Solution): Compute the value of “Y” from the equation Y=3x+2.
3 Calculate Y =3*X+2
Y=3*X+2
4 print value of Y
Print Y
5 End
End
(10)
Dear Student/ Notice
The word “Area” refers to a Variable name, whose value is
the calculated area of the rectangle; also “Perimeter” is a variable
name whose value is the calculated perimeter of the rectangle.
Output:
Input:
Solution :
(11)
There are many problems that contain a question requires a Yes or No, or requires
branching to other processes determined by flowchart.
End
(12)
First: Define the problem
Output: print the result of dividing two numbers “R” or print the word
“undefined"
Input: Numerator is “num1”, denominator is “num2”.
Solution: if num2=0 then print “undefined”, otherwise print the result of the
division “R”.
1 Start Start
5 R=num1/num2 R=num1/num2
6 Print R
Print R
7 End
End
Table (1-5) Algorithm and Flowchart to print the division of two numbers
Dear Student / Notice
1. Step (4) is a decision (represented by the rhombus shape)
It is a comparison that evaluates this question (is
num2=0?) If the result is Yes then the word “undefined"
will be printed according to mathematical rules; then the
execution will be transferred to step (7) to end the
program and prevent the execution of the division.
2. If the result of the condition in (step 4) is false, the
execution will be transferred to step (5) directly because
step (4-1) and (4-2) won’t be executed.
(13)
First: Define the problem
Output: print the number type (even or odd).
Input: the number “N”.
Solution: the even number is determined if the entered number is divisible by 2
without remainder, otherwise it will be odd.
Second :Algorithm Third :Flowchart
1 Start
Start
2 Enter N
End
Table (1-6) Algorithm and Flowchart to enter a number and print its type (odd or even)
(14)
Second :Algorithm Third :Flowchart
1 Start
Start
2 Enter D (temperature
degree)
Get D
3 If D=o then
5 End End
(15)
Flowchart Modified Flowchart
Start
Input R
A= 3.14 * R * R
Print A
End
(16)
Second :Algorithm Third :Flowchart
1 Start
Start
2 M=1
M=1
3 If M<=3 then
3-1 Print M
M<=3
3-2 M=M+1
4 End M=M+1
End
Start
End
You can track the progress of the solution steps and follow each step of the code as shown
in table (1-10).
(17)
Step value of M Result
1-Start There is No variable
2-M=1 1
3-If M<=3 (True) 1
1 3-1 Print M
3-2 M=M+1
1
2
1
Table (1-10) Tracking the variables and the corresponding result of exercise (1-7)
How many times was the content of the loop executed? ……………………
What will be the value of M after the end of the loop? ……………………………
(18)
Algorithm Flowchart
1 Start
Start
2 J=1
J=1
3 If J <=12 then
4 End End
Compare this flowchart to the one in the previous exercise (what are the differences?).
(19)
Make the necessary modifications to the Flowchart of the previous exercise, so that
you can enter the required multiplication table constantly instead of printing the
multiplication table of “3”.
Algorithm Flowchart
1 Start
2 Enter N
3 J=1
4 If J<=12 then
4-1 Print J*N
4-2 J=J+1
4-3 Go To step(4)
5 End
:Algorithm Flowchart
(20)
Algorithm Flowchart
1 Start
Start
2 N=1
N=1
3 Sum=0
Sum=0
4 Sum =Sum + N
Sum=Sum+N
5 N=N+1
N=N+1
6 If N>3 Then
7 Else
Print Sum
8 End End
Table (1-13) Algorithm and flowchart to print the sum of integer numbers from 1 to 3
You can track the values of variables as shown in table (1-14)
Step Value of N Value of Sum Result
1-Start No variable No variable
2-N=1 1 No variable
3-Sum=0 1 0
4-Sum=Sum+N 1 1
5-N=N+1 2 1
6-if N>3 (False) 2 1
7-1 Go To step (4) 2 1
4-Sum=Sum+N 2 3
5-N=N+1 3 3
6-if N>3 (False) 3 3
7-1 Go To step (4) 3 3
4-Sum=Sum+N 3 6
5-N=N+1 4 6
6-if N>3 (True) 4 6
6-1 Print Sum 4 6 6
Table (1-14) tracking the values of variables and corresponding results of exercise (1-9)
(21)
Dear Student / Notice
Variable N is considered a Counter, while variable Sum is used for
accumulation process.
(22)
First: Put () in front of the correct sentence and (X) in front of the wrong one:
(1) Flowcharts use standard symbols and lines to represent a problem algorithm. ) )
You can use any Geometric shape to represent Algorithm when drawing
(2) ) )
flowcharts.
(3) The symbol is used to represent start and end of flowchart. ) )
(4) The rectangle symbol is used to represent the data input operation. ) )
(5) The symbol is used to represent a decision process in flowcharts. ) )
(6) The problem means that an objective or output is required to reach. ) )
(7) Preparing a cup of tea is an example of a problem. ) )
Problem solving is the steps, activities, and processes to be done to reach an
(8) ) )
output or objective.
The program documentation is a set of procedures arranged logically for solving a
(9) ) )
specific problem.
(10) The program testing is writing down all the steps taken to solve a problem. ) )
(11) Documenting the program means making sure that the program is free of errors. ) )
(12) Algorithm is a set of procedures arranged logically for solving a specific problem. ) )
The program documentation is writing down all the steps taken to solve a
(13) ) )
problem.
(14) Testing the program means making sure that the program is free of errors. ) )
Flowcharts are diagram representations which depend on drawing some standard
(15) ) )
symbols to clarify the order of procedures to solve a problem.
Flowcharts help to facilitate understanding of the problem, analyse and convert it
(16) ) )
to a program.
Second: Choose the appropriate answer to complete each phrase of the following:
1- Steps, activities and procedures to be done to reach an objective or an output - can be
called:
a. problem definition b. problem c. problem solving
3- A set of procedures arranged logically for solving a specific problem – can be called:
a. problem b. algorithm c. program testing
5- Writing down all the steps taken to solve a problem errors – can be called:
a. program documentation b. program testing c. flowcharts
(23)
6- Problem-solving includes many terminologies, the terminology that expresses the
preparation of a cup juice is:
a. Flowchart b. algorithm c. problem
Start
M=1
FALSE
M<=3
M=M+1
TRUE
Print M
End
10- In Flowchart of the previous question, the value of M after the end of the iterative
loop equals:
a. 2 b- 3 c- 4
(24)