0% found this document useful (0 votes)
22 views7 pages

Flowchart Examples for Algorithms

The document provides examples of algorithms and pseudocode for various mathematical operations and conditions, including finding the square of a number, summing two numbers, calculating the area and perimeter of a rectangle, and categorizing individuals based on age. It also includes flowchart representations for these algorithms. Each example outlines the input, process, and output clearly, demonstrating how to structure algorithms effectively.

Uploaded by

fulhansdariya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views7 pages

Flowchart Examples for Algorithms

The document provides examples of algorithms and pseudocode for various mathematical operations and conditions, including finding the square of a number, summing two numbers, calculating the area and perimeter of a rectangle, and categorizing individuals based on age. It also includes flowchart representations for these algorithms. Each example outlines the input, process, and output clearly, demonstrating how to structure algorithms effectively.

Uploaded by

fulhansdariya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Flowchart — Visual Representation of Algorithms

Shapes or symbols to draw flow charts:-

Example 1: Write an algorithm to find the square of a number.


->Before developing the algorithm, let us first identify the input, process and output:
• Input: Number whose square is required
• Process: Multiply the number by itself to get
its square
• Output: Square of the number

Algorithm to find square of a number.


Step 1: Input a number and store it to num
Step 2: Compute num * num and store it in square
Step 3: Print square

.
Example 2: Draw a flowchart to solve the problem of a non-functioning light bulb.

Example 4.3: Write an algorithm to display the sum of two numbers entered by user, using
both pseudocode and flowchart. Pseudocode for the sum of two numbers will be:-
INPUT num1
INPUT num2
COMPUTE Result = num1 + num2
PRINT Result
Example 4: Write an algorithm to calculate area and perimeter of a rectangle, using both
pseudocode and flowchart. Pseudocode for calculating area and perimeter of a rectangle:-
INPUT length
INPUT breadth
COMPUTE Area = length * breadth
PRINT Area
COMPUTE Perim = 2 * (length + breadth)
PRINT Perim

Example 5: Let us write an algorithm to check whether a number is odd or even.


• Input: Any number
• Process: Check whether the number is even or not
• Output: Message “Even” or “Odd”
Pseudocode of the algorithm can be written as follows:-
PRINT "Enter the Number"
INPUT number
IF number MOD 2 == 0 THEN
PRINT "Number is Even"
ELSE
PRINT "Number is Odd"
Example 6: Let us write a pseudocode and draw a flowchart where multiple conditions are
checked to categorise a person as either child (<13), teenager (>=13 but <20) or adult
(>=20),based on age specified:

• Input: Age
• Process: Check Age as per the given criteria
• Output: Print either “Child”, “Teenager”, “Adult”

Pseudocode is as follows:-
INPUT Age
IF Age < 13 THEN
PRINT "Child"
ELSE IF Age < 20 THEN
PRINT "Teenager"
ELSE
PRINT "Adult"
Example 7: Write pseudocode and draw a flowchart to accept 5 numbers and find their
average.
Pseudocode will be as follows:

Step 1: SET count = 0, sum = 0


Step 2: WHILE count < 5 , REPEAT steps 3 to 5
Step 3: INPUT a number to num
Step 4: sum = sum + num
Step 5: count = count + 1
Step 6: COMPUTE average = sum/5
Step 7: PRINT average
Example 8: Write pseudocode and draw flowchart to accept numbers till the user enters 0
and then find their average.
Pseudocode is as follows:

Step 1: SET count = 0, sum = 0


Step 2: INPUT num
Step 3: WHILE num is not equal to 0, REPEAT Steps 4 to 6
Step 4: sum = sum + num
Step 5: count = count + 1
Step 6: INPUT num
Step 7: COMPUTE average = sum/count
Step 8: PRINT average

You might also like