KEMBAR78
Algorithms and Flowcharts | PDF | Algorithms | Fahrenheit
0% found this document useful (0 votes)
21 views10 pages

Algorithms and Flowcharts

The document explains algorithms as step-by-step instructions for solving problems and flowcharts as graphical representations of these algorithms. It outlines the advantages of using both tools, provides tips for writing algorithms, and details the symbols used in flowcharts. Additionally, it includes examples of algorithms for various tasks, illustrating their practical applications.

Uploaded by

sara
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)
21 views10 pages

Algorithms and Flowcharts

The document explains algorithms as step-by-step instructions for solving problems and flowcharts as graphical representations of these algorithms. It outlines the advantages of using both tools, provides tips for writing algorithms, and details the symbols used in flowcharts. Additionally, it includes examples of algorithms for various tasks, illustrating their practical applications.

Uploaded by

sara
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
You are on page 1/ 10

Algorithms

and
Flowcharts
What is an Algorithm?
An algorithm is a set of instructions that a computer follows to perform a specific task. It is a
step-by-step procedure that outlines the actions to be taken to solve a particular problem.

What is a Flowchart?
A flowchart is a graphical representation of an algorithm that uses symbols and arrows to
show the flow of instructions. It is a visual tool used to illustrate the steps involved in a
process.

Advantages of Using Algorithms and Flowcharts


• Provides a clear and concise way to understand a process
• Helps in identifying errors and inefficiencies in a process
• Facilitates communication between different stakeholders involved in a process
• Enables easy modification and improvement of a process

In addition to being used by technology, a lot of things we do daily are like algorithms.

Let's say you want to make some spaghetti. To do this


successfully, there's a certain set of steps you need to
follow in a particular order. First, you'll need to boil a pot
of water. Once it's boiling, you then add the
spaghetti and cook it for a set amount of time, stirring
occasionally. Once it's finished, you drain the water, then
it's ready to be served with a sauce of your choice.

This entire process is an algorithm. Because you followed these steps in a particular order,
you reached your desired outcome: a delicious pasta dish.

Difference between an algorithm and a flowchart


Steps for Creating a Flowchart
• Define the problem to be solved
• Break down the problem into smaller steps or processes
• Identify the decision points and input/output required
• Arrange the steps in a logical sequence
• Draw the flowchart using the appropriate symbols and arrows
• Test the flowchart to ensure it correctly solves the problem

Tips for Writing Algorithms


• Use clear and concise language
• Break down the problem into smaller steps
• Use meaningful names for variables and functions
• Consider efficiency and resource usage when designing an algorithm
• Test the algorithm with different inputs to ensure it produces the expected output

Symbols Used in Flowcharts

Start/End: Indicates the beginning or end of a process


Process: Represents a step in the process
Decision: Used to make a decision based on a condition or criteria
Input/Output: Shows the input or output of a process
Connector: Connects different parts of a flowchart

Flowcharts use a particular shape to denote each action so just by looking at the shapes used,
you know whether it is user input, some conditional statement, or some calculations being
done in a particular step. Different flowchart shapes have different conventional meanings.
The meanings of some of the more common shapes are as follows:

Terminator
The terminator symbol represents the starting or ending point of the system.
It is filled with either START/STOP as text to denote the starting or ending of the flowchart.

START/STOP

Process
A box indicates some operation or calculation being done on the data. We also use this shape
to initialize variables & constants.
Example usage:

Decision Box
A diamond represents a decision or a branching point. Lines coming out from the diamond
indicates different possible situations, leading to different sub-processes.

Example usage:

Data
It represents information entering or leaving the system. An input might be an order from a
customer. Output can be a product to be delivered.

Example usage:
On-Page Reference
This symbol would contain a letter inside. It indicates that the flow continues on a matching
symbol containing the same letter somewhere else on the same page.

Flow Lines
Lines represent the flow of the sequence and direction of a process.

Few Important points before we start:

Assignment Operator
Assignment values are assigned to an item/variable using the ← operator. The variable on
the left of the ← is assigned the value of the expression on the right.

Input and output statements


INPUT and OUTPUT are used for the entry of data and display of information
INPUT is used for data entry. It is usually followed by a variable where the data input is stored,
for example:
INPUT Name
INPUT StudentMark
OUPUT/PRINT is used to display information either on a screen or printed on paper.
PRINT Name
PRINT “Your name is”, Name
Example 1: Accept two numbers from the user and output which of them is greater
Algorithm:
• Step 1: Start
• Step 2: Read two numbers X and Y
• Step 3: Check if X > Y
• Step 4: If the condition is true, Print X
• Step 5: If the condition is false, Print Y
• Step 6: STOP
Example 2: Print numbers from 1 to 20
Algorithm:
• Step 1: START
• Step 2: Initialize X as 0
• Step 3: Increment X by 1
• Step 4: Print X
• Step 5: If X is less than 20 then go back to step 3
• Step 6: STOP

A Flowchart to Print the numbers 1 to 20


Example 3: Convert temperature from Fahrenheit (℉) to Celsius (℃)
Algorithm:
• Step 1: START
• Step 2: Read temperature in Fahrenheit,
• Step 3: Calculate temperature with formula C = 5 / 9 * (F - 32)
• Step 4: Print C
• Step 5: STOP

Example 4: Determine whether a student passed the exam or not


Algorithm:
• Step 1: START
• Step 2: Input grades of 4 courses M1, M2, M3 and M4,
• Step 3: Calculate the average grade with formula, Grade = (M1+M2+M3+M4) / 4
• Step 4: If the average grade is less than 60, print "FAIL", else print "PASS".
• Step 5: STOP
Example 5: Input two numbers and display their sum
Algorithm:
• Step 1: Start
• Step 2: Input two numbers, say A and B
• Step 3: Calculate the sum as sum = A + B
• Step 4: Print sum
• Step 5: Stop

Example 6: Determine if the given number is even or odd


Algorithm:
• Step 1: Start
• Step 2: Input a number, say Number
• Step 3: Divide the Number by 2 and check the remainder
• Step 4: If the remainder is equal to 0 then print “even” else print “odd”
• Step 5: Stop
Note: In coding, the modulus operator (represented as %) returns the remainder when the
first operand is divided by the second operand.
Example 7: Determine if the given number is positive, negative or zero
Algorithm:
• Step 1: Start
• Step 2: Input a number, say N
• Step 3: If N > 0 then print “positive” else if N < 0 then print “Negative” else print “zero”
• Step 4: Stop

You might also like