[go: up one dir, main page]

0% found this document useful (0 votes)
143 views20 pages

Algorithm & Flowchart 28-01-2025

The document provides a comprehensive overview of algorithms and flowcharts, detailing their definitions, characteristics, advantages, and disadvantages. It explains the step-by-step process of creating algorithms and flowcharts, along with examples for practical understanding. Additionally, it introduces pseudocode as a simplified method for representing algorithms.

Uploaded by

ohyeahdaddy.069
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)
143 views20 pages

Algorithm & Flowchart 28-01-2025

The document provides a comprehensive overview of algorithms and flowcharts, detailing their definitions, characteristics, advantages, and disadvantages. It explains the step-by-step process of creating algorithms and flowcharts, along with examples for practical understanding. Additionally, it introduces pseudocode as a simplified method for representing algorithms.

Uploaded by

ohyeahdaddy.069
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/ 20

HOW TO MAKE AN

ALGORITHM AND
FLOWCHART

SOURCE CODE
ALGORITHM
• An algorithm is a step-by-step procedure or a set of rules for
solving a specific problem or completing a specific task with finite
steps. It is a sequence of well-defined instructions.
• An algorithm is a step-by-step process to solve a given problem with
finite number of steps.
• Used to solve a mathematical or computer problem, this is the first
step in the process.
• An algorithm includes calculations, reasoning, and data processing.
CHARACTERISTICS OF AN ALGORITHM
• Input: An algorithm has zero or more inputs.
• Output: An algorithm produces at least one output.
• Definiteness: All instructions in an algorithm must be unambiguous, precise, and easy to interpret.
By referring to any of the instructions in an algorithm one can clearly understand what is to be done.

• Finiteness: An algorithm must always terminate after a finite number of steps. It means after every
step one reach closer to solution of the problem and after a finite number of steps algorithm reaches to
an end point.

• Effectiveness: An algorithm must be developed by using very basic, simple, and feasible operations
so that one can trace it out by using just paper and pencil.

Properties of Algorithm:
•It should terminate after a finite time.
•It should produce at least one output.
•It should take zero or more input.
•It should be deterministic means giving the same output for the same input case.
•Every step in the algorithm must be effective i.e. every step should do some work.
Advantages of Algorithms:
• It is easy to understand.
• An algorithm is a step-wise representation of a solution to a given problem.
• In an Algorithm the problem is broken down into smaller pieces or steps
hence, it is easier for the programmer to convert it into an actual program.

Disadvantages of Algorithms:
• Writing an algorithm takes a long time so it is time-consuming.
• Understanding complex logic through algorithms can be very difficult.
• Branching and Looping statements are difficult to show in Algorithms
FLOWCHART
• A flowchart is the graphical or pictorial representation of an algorithm
with the help of different symbols, shapes, and arrows to demonstrate a
process or a program.
• The main purpose of using a flowchart is to analyze different methods.

Advantages of Flowchart in C:
Communication: A flowchart is a better way of communicating the logic of a program.
Synthesis: Flowchart is used as working models in designing new programs and software
systems.
Efficient Coding: Flowcharts act as a guide for a programmer in writing the actual code in
a high-level language.
Proper Debugging: Flowcharts help in the debugging process.
• Effective Analysis: Effective analysis of logical programs can be easily done with the
help of a related flowchart.
• Proper Documentation: Flowchart provides better and proper documentation. It consists
of various activities such as collecting, organizing, storing, and maintaining all related
program records.
• Testing: A flowchart helps in the testing process.
• Efficient program maintenance: The maintenance of the program becomes easy with
the help of a flowchart.

Disadvantages of Flowchart in C:
Time-consuming: Designing a flowchart is a very time-consuming process.
Complex: It isn't easy to draw a flowchart for large and complex programs.
There is no standard in the flowchart; there is no standard to determine the
quantity of detail.
Difficult to modify: It is very difficult to modify the existing flowchart.
Difficult to reproduce the flowcharts.
Common symbols applied in a flowchart:
Terminal Box –Start / End

Input / Output

Process / Instruction

Decision

Connector / Arrow
S.No Algorithm Flowchart

1 An algorithm is a step-by-step process A flowchart is a graphical


to solve a problem. representation of an algorithm.
2 The algorithm is complex to A flowchart is easy to understand.
understand.
3 In the algorithm, plain text is used. In the flowchart, symbols/shapes are
used.
4 he algorithm is easy to debug. A flowchart is hard to debug.
5 The algorithm is difficult to construct. A flowchart is simple to construct.

6 The algorithm does not follow any The flowchart follows rules to be
rules. constructed.
7 The algorithm is the pseudo-code for A flowchart is just a graphical
the program. representation of that logic.
Now Let’s try
solving a
problem!!!
1. Compute the average of three numbers. FLOWCHART
ALGORITHM
• Step 1: Start START
• Step 2: Declare variables num1, num2, num3 and
average. Read num1,
num2 and
• Step 3: Read values of num1, num2 and num3. num3.

• Step 4: Find the average using the formula:


average =
average = (num1 + num2 +num3) / 3 (num1 + num2 + num3) / 3

• Step 5: Display average.


Display
• Step 6: Stop average

STOP
2. DETERMINE IF THE NUMBER GIVEN FLOWCHART
BY THE USER IS ODD OR EVEN.
ALGORITHM START
• Step 1: Start
Input number
• Step 2: Declare number and remainder.
remainder = number % 2
• Step 3: Input number.
• Step 4: Find the remainder of the number
divided by 2 using the formula: remainder == 0

remainder = number % 2 FALSE TRUE

• Step 5: Check:
ODD EVEN
if remainder == 0, then display “EVEN”.
else, display “ODD”.

• Step 6: End.
END
3. FIND THE LARGEST AMONG THREE DIFFERENT NUMBERS
ENTERED BY THE USER.
ALGORITHM
• Step 1: Start
• Step 2: Declare variables num1, num2, num3 and average.
• Step 3: Input num1, num2 and num3.
• Step 4: Check:
if num1 > num2 && num1 >num3, display “num1 is the largest”.
else, check:
if num2 > num3, display “num2 is the largest”
else, display “num3 is the largest”.
• Step 6: End.
START FLOWCHART
Input num1,
num2, num3

num1 > num2


&& FALSE
num1 > num3
TRUE
num2 > num3
num1 is the
largest TRUE FALSE

num2 is the num3 is the


largest largest

END
Algorithm of factorial of a number

Step 1: Start
Step 2: Read a number n
Step 2: Initialize variables: i = 1, fact = 1
Step 3: if i <= n go to step 4 otherwise go to step 6
Step 4: Calculate fact = fact * i
Step 5: Increment the i by 1 (i=i+1) and go to step 3
Step 6: Print fact
Step 7: Stop
Pseudocodes
A flowchart, algorithm, and pseudocodes are used to write
the steps to solve a particular problem. It is a brief form of
the algorithm. It removes the unnecessary English from the
algorithm.
A pseudocode is an informal way of writing a program in
structured English. It focuses on the logic of the algorithm
and does not go into the detail of the language syntax. It
can be directly converted into a program using a
programming language.
A pseudocode to add two A pseudocode to find the
numbers, A and B, in a greater of two numbers:
third number, C: 1. START
1. START 2. INPUT: Integer A and B
2. INPUT: Integer A and B 3. IF A > B, THEN print 'A is
3. C=A+B greater.'
4. Print C 4. ELSE IF print, 'B is greater
5. END 5. ELSE print 'The numbers are
equal
6. END
A pseudocode to find whether a number is even or odd:
1. START
2. INPUT: Integer A
3. IF A % 2 = = 0 THEN 'print the number is EVEN'
4. ELSE' Print the number is ODD.'
5. END

A pseudocode to swap two numbers:


1. START
2. INPUT: Integer A and B
3. T = A
4. A = B
5. B =T
6. PRINT A, B
7. END
Algorithm Flowchart Pseudocode
It is a plan for how to solve A flowchart is a pictorial It is an informal way
a problem step by step. representation of an of writing the program.
algorithm or steps for
solving a problem.
It is complex to It is easy to understand. It is hard to understand
understand. as compared to the
algorithm.
Text is used to write the Different shapes are used Text and mathematical
algorithm. to draw flowcharts. symbols are used to
write the algorithm.

Easy to debug. Hard to debug. It is hard to debug as


compared to the
algorithm.

You might also like