You are on page 1of 5

ALGORITHMS – PSEUDOCODES AND FLOWCHARTS

An algorithm describes how to carry out a process and gives the sequence of steps that need to be taken to solve
a problem. Two types of algorithms are:
Pseudocode:
A pseudocode describes the steps of a program in phrases of English.
 Pseudocodes are not real programs.
One can easily write a pseudocode without even knowing which programming language you will use for the
final program.
 There are no syntax or rules to be followed while writing pseudocode.
It cannot be compiled or executed.

Flowchart: A flowchart is a pictorial representation of a pseudocode. Each step in a flowcart is represented by a


different symbol/box depending upon the type of instruction. The arrows show the process of flow of direction. If
we know the purpose of each of the boxes, we can place all instructions in the correct boxes. Some of the boxes
used in basic flowcharts are shown below:

S. No. Box/Symbol and Name Purpose


This symbol indicates the beginning and ending
of a process.

1)
Ellipse or Oval Symbol
Known as Start or Stop Box
It tells about the input and output process. Values
to be accepted or any results to be printed are
placed here.
2)
Parallelogram
Known as Input/Output Box
This box represents all the procedures. Usually,
all calculations and other processing takes place
in this box.
3)
Rectangle Known as
Operations/Calculation/Process Box
This decision box is used to represent a decision
to be taken and to indicate the selected option.

4)
Rhombus or Diamond Shape
Known as Decision Box
It represents direction of flow of control and
Arrow Symbol shows relation between different shapes and
5)
Known as a Data Flow sequence of process steps.
Remember the following points:
 Variables in pseudocodes and flowcharts are usually indicated using capital letters.
 When a variable like A has to be printed, then the print statement is used as Print A.
 If a message needs to be printed, then it is shown within “”. For example, Print “Hello” where Hello is a message.
 To compare values, use the following signs: = (equal to), <> (not equal to), > (greater than), >= (greater than
or equal to), < (less than), <= (less than or equal to).

1) Write a pseudocode and draw a flowchart to accept two numbers and print their sum.
Pseudocode Flowchart
Step 1: Begin
Step 2: Read two numbers in A and B
Step 3: Add A and B and store the result in SUM
Step 4:Print SUM
Step 5:End

2) Write a pseudocode and draw a flowchart to accept two numbers and print their sum and average.
Pseudocode Flowchart
Step 1: Begin
Step 2: Read two numbers in A and B
Step 3: Add A and B and store the result in SUM
Step 4: Divide SUM by 2 and store the average in AVG
Step 5: Print SUM
Step 6: Print AVG
Step 7: End
3) Write a pseudocode and draw a flowchart to accept two numbers to check the greater.
Pseudocode Flowchart
Step 1: Begin
Step 2: Read two numbers in A, B
Step 3: If A>B, then
Print ”Equal”
Else
Print ”Not Equal”
Step 4: End

4)Write a pseudocode and draw a flowchart to accept a number and print whether it is an even number
or odd. When we divide an even number by 2, the remainder is 0. But for an odd number, it is 1.
Pseudocode Flowchart
Step 1: Begin
Step 2: Read a number in N
Step 3: Divide the number by 2
and store the remainder in R
Step 4:If R=0, then
Print ”Even”
Else
Print ”Odd”
Step 5: End

Note that the mod operation used in the


flowchart gets the result as remainder. To
get the quotient, we can simply write N/2.

Page 3
5) Write a pseudocode and draw a flowchart to accept side of a square and calculate and print its area
and perimeter.
Pseudocode Flowchart
Step 1: Begin
Step 2: Read side of square in S
Step 3: Calculate area as SxS and store
in A
Step 4: Calculate perimeter as 4xS and
store in P
Step 5: Print A, P
Step 5: End

6) Write a pseudocode and draw a flowchart to accept marks of a student and print whether the student
has got an A grade or not. A student gets an A grade if he secures 80 marks or above.
Pseudocode Flowchart
Step 1: Begin
Step 2: Read marks in M
Step 3: If M>=80, then
Print ”A Grade”
Else

Print “ No A Grade”

Step 4: End

Page 4
Loop: It is an Iterative statement.
It is the statement which gets executed repeatedly based on some condition. If the condition is true it enters into
the loop and executes the statements given in it, if the condition is false it comes out of the loop.

7) Write a pseudocode and draw a flowchart to find sum of “ n “ natural numbers.

Pseudocode Flowchart
Start
Step 1: Begin
Step 2: Declare 3 variables SUM , I , N.
Step 3: Accept n value Declare SUM , I , N
Read N
Step 4 : Initialize SUM=0 and I =1.
Step 5: Check whether I is less than or equal to N Read N
Or not,
If ( I <= N) Initiaise SUM=0 , I=1
i) Calculate SUM= SUM + I
ii) Go to step 5.
Else
Go to step 6. If F
Step 6: Print SUM. Print SUM
I <= N
Step 7: End.
T

SUM = SUM + I
I= I + 1 Stop

Page 5

You might also like