Introduction to programming and problem solving
Using C Language SPC 2101
Lesson 2: Topic Areas Flowchart vs algorithms vs Pseudo code in programming.
What is a Flowchart?
Flowchart: is a graphical representation of an algorithm. Programmers often use it as a
program-planning tool to solve a problem.
The purpose of a flow chart
The purpose of a flow chart is to provide people with a common language for understanding
a project or process.
Each flowchart represents a solution to a given problem definition. Flowchart is
prepared using following common symbols:
Here is a chart for some of the common symbols used in drawing flowcharts.
Symbol Symbol Name Purpose
Used at the beginning and end of the algorithm to show
Start/Stop start and end of the program.
Terminal
Indicates processes like mathematical operations.
Process
Rectangle
Used for denoting program inputs and outputs.
Input/ Output
parallelogram
Stands for decision statements in a program, where
answer is usually Yes or No.
Decision
Diamond
Shows relationships between different shapes.
Arrow
1|P ag e
Connects two or more parts of a flowchart, which are on
the same page.
On-page Connector
Connectors
Connects two parts of a flowchart which are spread
over different pages.
Off-page Connector
Guidelines for Developing Flowcharts
These are some points to keep in mind while developing a flowchart −
a) Flowchart can have only one start and one stop symbol
b) On-page connectors are referenced using numbers
c) Off-page connectors are referenced using alphabets
d) General flow of processes is top to bottom or left to right
e) Arrows should not cross each other
Advantages of Flowchart:
Flowcharts are a better way of communicating the logic of the system.
Flowcharts act as a guide for blueprint during program designed.
Flowcharts help in debugging process.
With the help of flowcharts programs can be easily analyzed.
It provides better documentation.
Flowcharts serve as a good proper documentation.
Easy to trace errors in the software.
Easy to understand.
The flowchart can be reused for inconvenience in the future.
It helps to provide correct logic.
Disadvantages of Flowchart:
It is difficult to draw flowcharts for large and complex programs.
There is no standard to determine the amount of detail.
Difficult to reproduce the flowcharts.
It is very difficult to modify the Flowchart.
Making a flowchart is costly.
Some developer thinks that it is waste of time.
It makes software processes low.
If changes are done in software, then the flowchart must be redrawn
2|P ag e
What is an Algorithm? Algorithm Basics
The word Algorithm means”
A set of rules to be followed in calculations or other problem-solving operations”
Or” A procedure for solving a mathematical problem in a finite number of steps
that frequently involves recursive operations”.
Characteristics of Algorithm
i) Input: An algorithm should take zero or more quantities as input, that are
externally supplied.
(ii) Output: An algorithm should produce at least one output.
(iii) Definiteness: Each and every instruction in an algorithm should be very
clear and unambiguous.
(iv) Finiteness: An algorithm must be such that if we trace out its instructions,
then for all cases, the algorithm terminates after a finite number of steps.
(v) Effectiveness: In an algorithm, every instruction must be very basic so that it
can be carried out, in principle, by a person using only pencil and paper or we
can say pen and paper. It is not enough that each operation be definite as in
criterion (iii). It must be feasible.
For example: In recursion, if we talk about factorial function. It could be given as :
(a) if n = 0, then n! = 1
(b) if n > 0, then n! = n. (n-1)!
If we write algorithm for finding factorial of any number, then it will follow all
above specified criteria in following manner:
(i) Input: A number n whose factorial is found.
(ii) Output: A number, i.e. factorial of number n.
(iii) Definiteness : Each instruction is definite, i.e. the function to be done is not
just multiply the number n with one less than that of it, i.e. n-1 means :
n(n-1).
(iv) Finiteness: Algorithm will terminate when n will become zero as 0! = 1.
(v) Effectiveness: Each instruction, i.e. n(n-1) is very basic and can be done using
pencil and paper.
Difference between Algorithm and function
a) Algorithm - is a series of steps (a process) for performing a calculation
b) Function - is the mathematical relationship between parameters and results.
3|P ag e
Difference between algorithm and flow chart:
No Algorithm Flowchart
An algorithm is a step-by-step A flowchart is a diagram created with different
1. procedure to solve a problem. shapes to show the flow of data.
2. The algorithm is complex to understand. A flowchart is easy to understand.
3. In the algorithm, plain text is used. In the flowchart, symbols/shapes are used.
4. The 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 rules. The flowchart follows rules to be constructed.
The algorithm is the pseudo-code for A flowchart is just a graphical representation of that
7. the program. logic.
Why do you need an Algorithm?
1. Scalability – when you have a sizeable real-world problem, you must break it
down into small steps to analyze it quickly.
2. Performance - The real world is challenging to break down into smaller steps. If
a problem can be easily dived into smaller steps, it indicates that the problem is
feasible.
Pseudo code
Pseudo code: - It’s simply an implementation of an algorithm in the form of
annotations and informative text written in plain English.
o It has no syntax like any of the programming language and thus can’t be
compiled or interpreted by the computer.
Advantages of Pseudocode
1. Improves the readability - of any approach. It’s one of the best approaches to start
implementation of an algorithm.
2. Acts as a bridge between the program and the algorithm or flowchart. Also
works as a rough documentation, so the program of one developer can be understood
easily when a pseudo code is written out. In industries, the approach of documentation is
essential. And that’s where a pseudo-code proves vital.
4|P ag e
3. The main goal of a pseudo code - is to explain what exactly each line of a program
should do, hence making the code construction phase easier for the programmer.
Pseudo code: Example AreaofTrinagle
A pseudocode to find the area of a triangle is as follows.
C program for triangle
AreaofTrinagle()
#include<stdio.h>
Begin
int main ()
{
Read: base, height;
float b, h, area;
Set area = 0.5 * base * height;
b= 5;
Print area;
h= 13;
area = (b*h) / 2 ;
End
printf("\n\n Area of Triangle is: %f",area);
5|P ag e return (0);
}
6|P ag e
7|P ag e
Exercise with solution
Draw the flow chart for finding largest of three numbers and write an algorithm and
explain it.
Solution
Algorithm:
1. Start
2. Input A,B,C
3. If (A>B) and (A>C) then print “A is greater”.
Else if (B>A) and (B>C) then print “B is greater”.
Else print “C is greater”.
4. Stop
8|P ag e
Revision Questions use Algorithm, flow chart and C program
1. calculating sum of integer 1 to 100 using C language draw Algorithm,
flow chart, program.
2. Design a program to find the circumference of a circle. Use the formula:
C=2πr, where π is approximately equivalent 3.1416.
9|P ag e