0% found this document useful (0 votes)
54 views23 pages

Algorithms and Flowcharts in C

Algorithm

Uploaded by

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

Algorithms and Flowcharts in C

Algorithm

Uploaded by

xzbunny1991
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

C PROGRAMMING

ALGORITHM AND
FLOWCHART
Agenda

 Algorithm

Definition

Properties of an Algorithm

Simple Examples

 Flowchart

Definition

Symbols used

Simple Examples
ALGORITHM

INTRODUCTION
An algorithm is a sequence of instructions that are carried out in a predetermined
sequence in order to solve a problem or complete a work. A function is a block of
code that can be called and executed from other parts of the program. A set of
instructions for resolving an issue or carrying out a certain activity. In computer
science, algorithms are used for a wide range of operations, from fundamental math to
intricate data processing. One of the common algorithms used in C is the sorting
algorithm. A sorting algorithm arranges a collection of items in a certain order, such as
numerically or alphabetically.
Definition
Algorithm is a well-defined, step-by-step procedure or formula for solving a problem
or performing a task. It serves as a blueprint for writing the code that achieves the desired
result.
Properties of an Algorithm

• Inputs: Algorithms must receive inputs that can be represented as values or data.

• Output: The algorithm should produce some output. It can be a consequence of a


problem or a solution designed to solve it.

• Clarity: Algorithms must be precisely defined, using unambiguous instructions that a


computer or other system can follow unambiguously.

• Finiteness: The algorithm requires a limited steps. It means that it should be exited
after executing a certain number of commands.
Properties of an Algorithm

• Validity: The algorithm must be valid. In other words, it should be able to produce a
solution to the problem that the algorithm is designed to solve in a reasonable amount
of time.

• Effectiveness: An algorithm must be effective, meaning that it must be able to produce


a solution to the problem it is designed to solve in a reasonable amount of time.

• Generality: An algorithm must be general, meaning that it can be applied to a wide


range of problems rather than being specific to a single problem.
Example of Algorithm

Exampl1: Write an algorithm to read two numbers and find their sum.
Inputs to the algorithm:

First num1.
Second num2.

Expected output:

Sum of the two numbers.


Algorithm:

Step1: Start

Step2: Read\input the first num1.

Step3: Read\input the second num2.

Step4: Sum num1+num2 // calculation of sum

Step5: Print Sum

Step6: End
Example of Algorithm

Example 2: Algorithm for finding the average of three numbers is as follows

Step1: Start

Step2: Read 3 numbers a,b,c

Step3: Compute sum = a+b+c

Step4: Compute average = sum/3

Step5: Print average value

Step6: Stop
Example of Algorithm

Example 3: Algorithm to check whether the input numbers is even or odd

Step1: Start

Step2: Enter a number in a

Step3: Check if it is even or odd

Step4: If even print “even”

Step5: Else odd print “odd”

Step6: Stop
Advantages of Algorithm

1. You can easily understand the motive of the program.

2. Help in searching / identifying the error.

3. Help in correcting the errors.

4. Help to write a complex program in an easy way as because algorithm solves any
problem / program step - by - step.
FLOWCHART
The Flowchart is the most widely used graphical representation of an algorithm and
procedural design workflows. It uses various symbols to show the operations and decisions
to be followed in a program. It flows in sequential order.

 Flowchart Symbols

There are 6 basic symbols commonly used in flowcharting of assembly language


Programs: Terminal, Process, input/output, Decision, Connector and Predefined Process.
This is not a complete list of all the possible flowcharting symbols, it is the ones used most
often in the structure of Assembly language programming.
 Notations used in Flowchart
Notations used in Flowchart

Terminal Symbol: In the flowchart, it is represented with the help of a


circle for denoting the start and stop symbol. The symbol given below is
used to represent the terminal symbol.
Notations used in Flowchart

Input/output Symbol: The input symbol is used to represent the input


data, and the output symbol is used to display the output operation. The
symbol given below is used for representing the Input/output symbol.
Notations used in Flowchart

Decision Symbol: Diamond symbol is used for represents decision-making statements.


The symbol given below is used to represent the decision symbol.
Notations used in Flowchart

Flow lines: It represents the exact sequence in which instructions are executed. Arrows are
used to represent the flow lines in a flowchart. The symbol given below is used for
representing the flow lines:
Notation used in Flowchart
Examples of Flowcharts
Design a flowchart for addition of two numbers.
Examples of Flowcharts

Example 2:Flowchart for the problem of printing even or odd number


Examples of Flowcharts

Example 2: Design a flowchart for checking whether the number is


positive or negative according to the number entered by the user.
ALGORITHM AND FLOWCHART WITH CODE

To Find Sum Of Number


THANK YOU

You might also like