0% found this document useful (0 votes)
6 views

Pseudocode

Pseudocode is a step-by-step description of a computer program or algorithm, written in plain English-like structure, and serves as a planning tool for programmers. It uses specific keywords to indicate operations and conditions, and can be represented alongside algorithms and flowcharts. The document includes examples of pseudocode for various scenarios, such as adding numbers and determining the largest of two inputs.

Uploaded by

sixthbit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Pseudocode

Pseudocode is a step-by-step description of a computer program or algorithm, written in plain English-like structure, and serves as a planning tool for programmers. It uses specific keywords to indicate operations and conditions, and can be represented alongside algorithms and flowcharts. The document includes examples of pseudocode for various scenarios, such as adding numbers and determining the largest of two inputs.

Uploaded by

sixthbit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1 Pseudocode


A Pseudocode is a step-by-step description of a computer program or an
algorithm.

Pseudocode is not a programming language.

Pseudocode is written in code like structure using plain English text.

Flowchart is an alternative to Pseudocode.

Example:
BEGIN
IF you are happy
THEN smile
ENDIF
END

Algorithm : a sequence of steps or instructions to solve a problem.


2 Why Use Pesudocode ?


It helps the programmer in planning the solution to the problem.

It helps others to understanding the approach to the problem.
3 Keywords

In Pseudocode, they are used to indicate common input-output and
processing operations. They are written fully in uppercase.

START/BEGIN : This is the start of your pseudocode.

END : Marks the end of your pesudocode.

INPUT : Retrieve data from the user.

PRINT, DISPLAY : This will show your output to a screen or the relevant output device.

IF-THEN-ELSE-ENDIF : To handle conditions


4 Writing Pseudocode. - Input/Output

Pseudocode to ask for the name and age, and then print a greeting :
BEGIN
INPUT name
INPUT age
PRINT "Hello " + name + ", you are " + age + " years old."
END
5 Adding Two Numbers.
Algorithm:

Start

Input the first number.

Input the second number.

Add the two numbers together.

Display the result.

End

Pseudocode:
BEGIN
INPUT first_number
INPUT second_number
sum = first_number + second_number
PRINT sum
END

* Exercise – Draw the flowchart for above pesudocode.


Conditions : IF-THEN-ELSE-ENDIF
6 Find the largest number between two inputs.

Algorithm: Pseudocode:

Start BEGIN

Input the first number. INPUT first_number

Input the second number. INPUT second_number

If the first number is greater than the second number then IF first_number > second_number THEN

Display the first number as the largest. PRINT first_number

Else
ELSE

Display the second number as the largest.
PRINT second_number

End If
END IF

End
END
Using ELSEIF
7
BEGIN

INPUT temperature

IF temperature > 30 THEN

PRINT "It's hot outside!"

ELSEIF temperature >= 20 AND temperature <= 30 THEN

PRINT "The weather is nice!"

ELSE

PRINT "It's cold outside!"

END IF

END

Exercise : Draw a flowchart for above pesudocode


8 EXERCISES
1) Write the algorithm,pesudocode and flowchart for a program that asks the user to enter a number. The
program should then check if the number is positive, negative or zero and display an appropriate message.

2)Write a pesudocode for a program that asks user for name and age. Then it should display <name> you
are <an adult/teenager/child>

3) Write the pesudocode for the following flowchart

Start

Input
number

Yes
If
Number % 2 = 0 Print “Even”

No

Print “Odd”

End

You might also like