4. 1st Basic Operation : Input
• When a computer is required to take an input from a particular source,
whether it is a terminal, a disk or any other device, the verbs Read and
Get are used.
• Example :
• You are writing an essay in MS word
• Computer reads/gets 2 values to add them up
4
5. 2nd Basic Operation : Output
• When a computer is required to provide output to a device, the verbs
Print, Write, Output, or Display are used in pseudo code.
• Usually an output Prompt instruction is required before an input Get
instruction.
• Example :
• You are viewing and printing your essay
• Computer displays / writes the added result of 2 values
5
6. 3rd Basic Operation : Processing
• Arithmetic Operations:
• Mathematical calculation, Formula, and for these, a programmer uses either
actual mathematical symbols or the words for those symbols.
• Comparison or Logical Operations:
• A computer can compare two variables and select one or two alternate
actions
• Example:
X = 5,Y = 7 X >Y OR X <Y
Z = X +Y
Z = 5 + 7
Z = 12 6
7. 4th Basic Operation : Storage
• An information is stored in some location in memory called Variable.
• 3 situations when need to store a value to a variable or memory location:
• To give data an initial value in pseudo code, the verbs Initialize or Set are used
• To assign a value as a result of some processing the symbols '=' or ‘' are
written
• To keep a variable for later use, the verbs Save or Store are used
• Example:
• You are downloading a song in your laptop
• Z = X +Y or Z X +Y
7
8. Problem to Solve
What steps would you propose to solve the following problem?
Your hair are dirty/greasy and want to clean up
8
9. Problem to Solve
• Problem:
Hair are dirty
• Solution:
Wash the hair
• How:
Wash the hair Algorithm
Algorithm
• Turn on water tab
• Wet you hair
• Apply shampoo
• Wash
• Rinse hair
• Dry off
9
10. Steps in Problem Solving (in computer
programming)
• Computer programming can be divided into two phases:
• Problem solving phase
• Make an ordered sequence of steps that solves a problem
• These sequence of steps is called an algorithm
• Implementation phase
• Implement using a programming language
10
11. Steps in Problem Solving
• First produce a general algorithm (one can use pseudocode)
• Refine the algorithm successively to get step by step detailed
algorithm that is very close to a computer language.
• Pseudocode is an informal language that helps programmers
develop algorithms. Pseudocode is very similar to everyday
English.
11
12. Pseudocode & Algorithm
•Example 1:Write an algorithm to determine a student’s
final grade and indicate whether it is passing or failing.The
final grade is calculated as the average of four marks.
12
13. Pseudocode
Pseudocode:
• Input a set of 4 marks
• Calculate their average by summing and dividing by 4
• if average is below 50
Print “FAIL”
else
Print “PASS”
13
15. Characteristics of Algorithm
• Definite and having Input and Output
• Well-ordered
• The steps are in a clear order
• Unambiguous
• The operations described are understood by a computing
agent without further simplification.
• Effectively Computable
• The computing agent can actually carry out the operation
15
16. Rules of Algorithm
• For Input:
Use keyword “Input” or “Get”
followed by a list of variables
separated by a single comma.
Example
Input a
Input a , b
Get a
Get a,b
• For Output:
Use keyword “Output”,
“Display” or “Print” followed by
a variable name or text.
Enclose “text/message” in
inverted commas. Do not
enclose variable name in
inverted commas.
Example
Output “Enter a number”
Display “Your number is ”
num
16
17. Rules of Algorithm
• Storage/ Assignment
Use the keyword “Set” in combination with “=” or “:=” OR use
keyword “=”, “:=” or “<-”
Example
Set X=8
X=8
Set X:=8
X:= 8
X<- 8
17
18. Addition ofTwo Numbers
• Input: number1 and number2
• Output: Sum of number1 and number2
• Steps:
1. Start
2.Input number1 , number2
3. Sum = number1 + number2
4.Display Sum
5.End
18
20. Pseudo code & Flowchart
• There are two commonly used tools to help to build logic (algorithm).
• Pseudo code is an artificial and informal language that helps programmers
develop algorithms.
• Pseudo code may be an informal English, combinations of computer
languages and spoken language.Whatever works for you.
• A Flowchart is another algorithm but graphical that shows logic solution.
• Emphasizes individual steps and their interconnections.
• A flowchart must have a start and stop.
• A step in a flowchart must connect i.e.You can’t leave a step “hanging”
with no connection. e.g. control flows from one action to the next
20
21. What is flow chart?
• The flowchart is one of the most basic methods of representing
algorithms. It is useful as a precise method of explanation in
some circumstances.
• A flowchart is a diagrammaticpictorial representation of the
operations involved in a data processing system.
21
22. Flow chart Symbols
• Start/End
• Used at the beginning and end of each flowchart.
• Input / Output
• Shows when information/data comes into a program or is
printed out.
• Process
• Used to show calculations, storing of data in variables, and
other “processes” that take place within a program.
22
23. Flow chart Symbols
• Decision
oUsed to show that the program must decide whether
something (usually a comparison between numbers) is true or
false.YES and NO (orT/F) branches are usually shown.
• Connector
oUsed to show that flowchart continues on another page.
• Flow Direction
oShow you how you have to move
23
X>7? Y
N
24. Example
Algorithm
• Step 1: Input W,L
• Step 2: A L x W
• Step 3: Print A
START
Input
W, L
A L x W
STOP
Output
W, L
24
25. Example
Input M1,M2,M3,M4
GRADE (M1+M2+M3+M4)/4
if (GRADE <50) then
Print “FAIL”
else
Print “PASS”
endif
START
Input
M1,M2,M3,M4
GRADE(M1+M2+M3+M4)/4
IS
GRADE<50
STOP
Y
N
Print “PASS” Print “FAIL”
25