Professional Documents
Culture Documents
Psedocode - Intoduction To Information Technology-1
Psedocode - Intoduction To Information Technology-1
Pseudocodes
Lesson-2
Objective
Commands: Example:
Read
Read name
Get
Get system_date
Input
Input marks
Put out Information
When computer is requested to supply information
output information to a device
Printer, File, Screen
Commands: Example:
Print Print “Command Print”
Write Write student_record to master file
Put Put name, address
Output Output grade
Display Display “Error code. Please re-
enter…”
Arithmetic Operation
A program can contain arithmetic operations and
computer has to perform those.
Commands: Example:
+ Add Add score to total_score
- Subtract total_score = total_score + score
* Multiply Divide total_marks by no_of_subjects
/ Divide average = total_marks/no_of_subjects
() Parentheses Compute C= (F-32) * 5/9
Compute
Assign a Value to a Variable or a
Memory Location
Give an initial value to a data
Assign a value as a result after doing some
processing
Keep some information for later use
Commands Example:
Initialize Initialize total_score to 0: total_score = 0
Set Set student_count to 0: student_count = 0
Store total_score = total_score + score
total_student = total_student + 1
Store average in class_average
Control Structures Of a Program
Sequence
Use set of instructions one after the other
Selection
Use IF … THEN … ELSE
Repetition
Use WHILE, DO … WHILE, FOR…
Sequence
• In a sequence control structure, statements are executed in
the same order as they are written.
STAR Pseudocode;
T
Statement 1 statement 1
Statement 2 statement 2
Statement 3 statement 3
STOP
IF …. THEN …. ELSE
If the condition is true do the statements inside IF
If the condition is false do the statements inside ELSE
Selection
ENDIF
Selection
Example2:
IF <condition> THEN
IF a>b THEN
sequence 1 Print a
ELSE ELSE
sequence 2 Print b
END IF
ENDIF
Exercises…
Write a pseudo code that inputs two
numbers (a and b) and output the largest
number.
INPUT a
INPUT b
IF a < b THEN
OUTPUT b
ELSE
OUTPUT a
END IF
Repetition
Same sequence of operations need to be repeated
Use
WHILE … ENDWHILE
DO WHILE … ENDDO
FOR … ENDFOR
The WHILE Loop
true
EndWhile
Statement
sequence
Exercises
Write a pseudo code that inputs ten numbers and
outputs the sum and average of them.
count = 1
sum = 0
WHILE count <= 10
INPUT a
sum = sum + a
count = count + 1
END WHILE
average = sum / 10
OUTPUT sum, average
The DO – WHILE Loop
Do
DO
Sequence
Statement
sequence
WHILE <condition>
false
Condition
?
true EndWhile
Exercises
For
FOR iteration bounds
Control_value = expression
sequence
ENDFOR
Control_value false
< end_value
?
true
Statement-sequence
Control_value = Control_value +1
Stop
Example…
Write a pseudo code that inputs ten numbers and outputs the
sum and average of them.
sum = 0
average = 0
FOR count = 1 to 10
INPUT a
sum = sum + a
END FOR
average = sum / count
OUTPUT sum, average
The NESTED Loop
The constructs can be embedded within each other, and
this is made clear by use of indenting
Nested constructs should be clearly indented from their
surrounding constructs
SET total to zero
WHILE Temperature < zero
INPUT Temperature
END WHILE
OUTPUT total