0% found this document useful (1 vote)
264 views7 pages

Algorithm and Flowchart

This document discusses the steps involved in problem solving and algorithm development. It begins by explaining that a computer must be precisely instructed by a user to solve problems, as computers have no intelligence of their own. It then outlines the key stages of problem solving as: 1) Understanding the problem, 2) Analyzing the problem, 3) Developing a solution, and 4) Coding and implementation. Next, it delves into the specific steps of algorithm development, including defining the problem, stating the steps to solve it clearly and in order, and ensuring the algorithm has properties like finiteness, definiteness, effectiveness, and generality. It provides an example algorithm for finding the largest number among three inputs.

Uploaded by

atulya
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 (1 vote)
264 views7 pages

Algorithm and Flowchart

This document discusses the steps involved in problem solving and algorithm development. It begins by explaining that a computer must be precisely instructed by a user to solve problems, as computers have no intelligence of their own. It then outlines the key stages of problem solving as: 1) Understanding the problem, 2) Analyzing the problem, 3) Developing a solution, and 4) Coding and implementation. Next, it delves into the specific steps of algorithm development, including defining the problem, stating the steps to solve it clearly and in order, and ensuring the algorithm has properties like finiteness, definiteness, effectiveness, and generality. It provides an example algorithm for finding the largest number among three inputs.

Uploaded by

atulya
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/ 7

250

Computer ScenceandEagineering

0 ntrodiuction
A computersavery powerful and versatile machine capableofperfoming
a multitude of differenttasks,yet it has no intelligence or thinking power The
intelligence Quotient (T.Q) ofa computer is zero. Acomputer performs many
tasks exactly in the same manner as it is told to do. This places responsibi
on
the user to instruct the computer in a correct and precise manner, so that the
is
machine able to perform the required job in a proper way. A wrong or
ambiguous instruction may sometimes prove disastrous.

In order to instruct a computer correctly, the user must have clear


UNIT understanding ofthe problem to be solved. A part from this he should be able to
develop a method, in the form of series of sequential steps, to solve i. Once the
problem is well-defined and a method ofsolving it is developed, then instructing

Introduction to Problem Solving he computer to soBve the problem becomes relatively easier task.

Techniques Thus, before attempt to write a computer program to solve a given problem.
It is necessary to formulate or define the problem in a precise manner. Once the
problem is defined, the steps required to solve it, must be stated clearly in the
required order.

Structure rocedure (Steps tnvolved inProblenSohving


1.0 Introduction
A computer cannot solve a problem on ts own. One has to provide step
1.I Procedure (steps imvolved in problem solving) by step solutions ofthe problem to the computer. In fact, the task of problem
solving is not that of the computer. It is the programmer who has to write down
12Algorithm the solution to the problem in terms of simple operations which the computer
13 Flow Chat can understand and execute.
1.4 Symbos used im Inorder to solve a problem by the computer, one has to pass though certain
Flow Charts stages or steps. They are
1.5 Pseudo Code
1. Understanding the problem
Learning Objectives 2. Analyzing the problem
To understand the concept of Problem solving
3. Developing the solution
To understand steps involved in
algorithm development
To understand the
4. Coding andimplementation
concept ofAlgorithm
Devetop Algorthm for simple problem
1. Understanding the problem: Here we try to understandthe problem
to be solved in totally. Before with the next stage or step, we should be absolutely
To understand the sure about the objectives of the given problem.
concept of Flowchart development
Draw the symbols used n Flowcharts 2. Analyzing the problem: Aftcr understanding thoroughly the problem
to be solved, we look different ways ofsolving the problem and evaluate each
Paper rogramaing in C Computer Science and Engineering
251 252

of these methods The idea here is to search an


appropriate solution to the Step5: Processing Finiteness: Ifwe go through thealgor then for
problem under consideration. The end resuh ofthis stage is a broad overview of
the sequence ofoperations that are to be carries out to solve the all cases, the algorithm should teminate after a finite number ofsteps
given problenm
3. Step6: Possessing Effectiveness: The instructions inthe algorithm
Developing the solution: Here the overview of the
sequence of must be sufficiently basic and in practice they can be carries out easily
operations that was the result of analysis stage is expanded to form a detailed
step by step solution to the problem under consideration An algorithm must possessthe following properties
4 Coding and
implementation: The last stage of the
problem sotving is 1. Finiteness: An algorithm must terminate in a finite number of steps
the conversion of the detaied sequence of
operations in to a language that the Each step of the
conputer can understand Here each step s comverted to ts equivalent instruction 2. Definiteness:
unambiguously stated
algorithm must be precisely and
or nstructons in the computer anguage that has been chosen for the implantation
1.2Algorithm 3. Efectiveness: Each step must be effective, in the sense that it should
be primitive easily convert able into program statement) can be
Definition in a finite amount
perfomed exacty
oftime.
A set of sequential steps usually written in Ordinary Language to solve a 4.
Generality: The algorithm must be complete in itself so that it can be
given problem is called Algorithm used tosolve problems ofa specific type for any
input data.
It may be possible to solve to
problem in more than one ways, resulting in 5. Input/output: Each
algorithm must take zero, one or more quantities as
more than one algorithm. The choice of various
factors like reliability, accuracy and easy to
algorithms depends on the input data produce one or more output values. An algorithm can be written in
modify. The most important factor in English like sentences or in any standard representation sometimes,
the choice ofalgorithmis the time
requrement to execute t, after wrting code in written in English like languages are called Pseudo Code algorithm
High-level language with the help ofa computer The algorithm which wil need
the east time when executed is considered the best. Example
Steps invoved in algorithm development 1. Suppose we want to find the
as follows
average of three numbers, the algorithm is
An algorithm can be defined as "a
complete, unambiguous, fîinite number
oflogical steps for soving a specific problem" Step 1 Read the numbers a, b, c

Step1. Identification of input For an algorithm, there are quantities to Step 2 Compute the sum of a, band c
be supplied called input and these are fed
first for any spec1tied
extemaly The
input isto be indentified Step 3 Divide the sum by3
problem
Step 4 Store the result in variable d
Step2: Identification ofoutput: From an algorithm, at east one quantity
Is produced, called for Step 5 Print the value of d
any specified problem
Step3: ldentification the processing operations All the Step 6 End of the program
to be calculations
perfomed in order to ead to output from the input are to be identified in 1.2.2 Algorithms for
an orderty manner. Simple Problem
Write an algorithm for the following
Step4: Processing Definiteness The instructions
algorithm must be clear and there should not be any ambiguity incomposing
the
I. Write an
them algorithm to calculate the simple interest using the formula.
Simple interest= p*N* R/100.
254 Compater Sdence and Eagineering
Paper Programmingin C 23
4. Write down an algorithm to find the largest data value of a set of given
Where Pis principle Amount, N is the number ofyears and R is the rate data values
of interest

Read the three input quantities' P, N and R


Algorithm largest of all data values:
Step 1
Step 1: LARGE-0
Step 2 Caculate simple interest as
N* R/100 Step 2: read NUM
Simple interest=P*
Step 3: While NUM> =0 do
Step 3 Print simple imterest.
3.1 ifNUM>LARGE
Step 4: Stop.
3.1.1 then
3.1.1.1 LARGE-NUM
2.Area of Triangle Wrte an algorithm to find the area
ofthe triangle. 3.2. read NUM
Letb.cbe the sadesofthetriangle ABC and Athe included angle between
the given sides. Step 4: Write "largest data value is", LARGE
Step 1: Input the given elements ofthe triangle namely sides b, cand angle Step 5: end.
between the sides A.
Step 2: Area =(1/2) *b°C sin A
Step 3 Output the Area
5. Write an algorithm which will test whether a givenitegervah1e s priume
or not.
Step 4. StopP Algorithm prime testing:
Step 1: M-2
3. Write an algorithm to find the largest ofthree numbers x, YZ. Step 2: readN
Step 1 Read the numbers Xx,Y.Z. Step 3: MAXSQRT(N)
Step 2: if(X>Y) Step 4: While M<=MAX do
Big=X 4.1 if (M* (N/M) =N
else BIG Y 4.1.1 then
Step 3 if (BIG<Z)
4.1.1.1 go to step 7
Step4: Big =z 4.2.M-M+1
Step 5: Print the largest number i.e. Big
Step 5:Write "number is prime"
Step 6: Stop.
Step 6: go to step8

Step 7: Write "number is not a prine'"

Step 8 end
Compater Scienceand Engíneering
256
in C
Paper Programam ing 255
Step S: Print perimeter.
6 Write algorthm to find the factorial ofa given number N
Step 6: Print area.

Step 1 PROD-1|
Step 7: Stop
Step2 1-0

Step 3 read N T3 Flowchart


of the log*
A flow chart is a step by step diagrammatic representation
Step4 While I< N do paths to solve a given problem Or Aflowchart is visual or graphical representation
411-1+1 ofan algorithm.
4.2.PROD-PROD* The flowcharts are pictorial representation ofthe methods tobused
to solve a given problem and help a great deal to analyze the problem and plan
Step 5 Wrte "Factorial of", N, "is", PROD
its solution in a systematic and orderly manner. A flowchart when translated in
Step 6 end to a proper computer language, results in a complete program
7 Write an algorithm to find sum of given data values until negative value is Advantages of FPloweharts
cniered
1. The flowchart shows the logic ofa problem displayed in pctorial fashion
Algorthm Find- Sum which felicitates easier checking ofan algorithm
Step 1 SUM-0
2. The Flowchart is good means ofcommunication to otheT users. It is also
Step 2 1 0 a compact means of recording an algorithm solution to a problem
Step 3: read NEW VALUE 3. The allows
flowchart solver to break the problem mto
the problem
These parts can be connected to make master chart.
parts
Step 4 While NEW VALUE< = 0 do

4. The flowchart is a permanent record of the solution which be


41 SUM- SUM+NEWw VALUE consulted at a later time.
can

421-1+1 Differences between Algorithm and Flowchart


43 read NEW VALUE Algorithm
Step 5: Wrie "Sum of", I, "data value is, "SUM
Flowchar
|1. A method of representing the 1. Flowchart is diagrammatic
Step 6 END step-by-step logical procedure for|representation of algorithm. It is|
an
solving a problem constructed using different types of boxes|
8 Wrneanalgorthm to calculate the perimeter and area ofrectangle Given
2. It contains step-by-step English|and symbols.
ts kength and width.
descriptions, each step
representing|2.
The flowchart employs a series
ofblocks|
Step1 Read kength of the rectangle particular operation leading to|and arrows, each of which represents a
Step 2 Read width ofthe rectangle solution of problem particular step in an algorithm
3. These are particularly useful for|3. These are useful for detailed
Step 3 Caculate perimeter of the rectangle using the formula perimeter= small problems
2* (length + width) representations of complicated programs
4. For complex programs,|4. For complex programs,
Step 4 Calculate area of the rectangle using the formula area length algorithms prove to be Inadequate prove Flowcharts
=
to be adequate
width
Paper 1 Programming in C 257 258 Computer Sdenceand Eazineering
pages are to be joined with each other. The parts to be joined are indicated by
1.4 Symbols used in Plow-Charts the circle.
below
The symbols that we make use while drawing flowcharts as given
are as per conventions followed by International Standard Organization (ISO)
a.
Oval Rectangle with rounded sides is used to indicate either START/
STOP ofthe program. .
m the path of
g. Of-page connectors: This conmector represents a break
flowchart which is too large to fit on a page. It
single is similar
to
on-page
connector. The connector symbol marks where the algorithm ends on the firS
b Input and output indicators: Parallelograms are used to represent page and where it continues on the second.
input and output operations. Statements like INPUT, READ and PRINT are
represented n these Paralelograms.

1.4.1 Simple Problems using Flow Chart


cProcess Indicators - Rectangle is used to indicate any set ofprocessing
operation such as for storing arithmetic operations. Draw the Flowchart for the following
1. Draw the Flowchart to find Roots of Quadratic equation ax+ bx+c
= 0. The coefficients a, b, c are the input data

START
d Decision Makers: The diamond is used for indicating the step of
decision making and therefore knowm as decision box Decision boxes are used
to test the conditions or ask questions and depending upon the answers, the NPUT AB,C
approprate actions are taken bythe computer. The decision box symbol is

D--4A*C

Flow lines indicate the direction being followed in the


c. Flow Lines:
fiowchart. In a Flowchart, every lime must have an arrow on it to indicate the
direction The arrows may be in any direction Is

D-O
NO

2A TA
£ On-Page connectors: Circles are used to join the different parts ofa Priat XY7
flowchart and these circles are called
on-page connectors. The uses
of these
connectors grve a neat shape to the flowcharts. Ina complicated problems, a
Towchart may run in to several The
pages. ofthe
parts on different
flowchart Stop
260 2 Computer Science and Engineering
Programming in C 259
Paper
4. Draw a flowchart to find the factorial of given positive integer N.
2. Draw aflowchart to find out the biggest of the three unequal positive
numbers. START

START
iNPUT

PROD=1
NO

YES

PRINT A PRINTC PRINT B


NO
l+1
oUTPUT

PROD

STOP
LPROD= PROD *1I
5. Develop a flowchart to illustrate how to make Land
3. Draw a flowchart for adding the integers from 1 to 100 and to
a phone
telephone call
print the sum.

TALK TO THE
SIAR PERSON AT THE
START OTHER END

NO PICKUP THE KEEP DOWN THE


SUM- SUM NN RECEIVER RECEIVER
LW-N
STOP

DIAL THE
NUMBER STOP

Flowchart for Telephone call


Paper - I Programming in C
261
Compater Scienceand Engineering
6. 6. ABC company plans to give a 6% year-end bonus to each of
its
employees earning Rs 6,000 or more per month, and a fixed Rs 250/- Activi
********* ***

bonus to the remaining employees. Drawa flowchart


bonus for an employee
for calculating
the Practice more sample problems onalgorthm and Flowcharts

START
Model Ouestions
Short Answer p e Questions2Mark
***********xensoek***********************
* * * ** * * * *

INPUT SALARY 1. Define Algorithm


OF AN EMPLOYEE
2. What is Flowchart
NO IS SALARr YES
3. What is Pseudo code?
4. What are the symbols of Flowchart
LDONUs 250 BONUs =0.06 *SALARY 5. Write an Algorithm for perimeter ofTriangle
6. What are the basic steps involved In problem solving
OUTPUT
Long Answer Type Ouestions6Markk
STOP 1. Differentiate betweenAlgorithm and Flowchart

1.5Pieudo code . e . . .
2. Write an algorithm to find greatest ofgiven three numbers
The Pseudo code is neither an algorithm nor a program. is an 3. Write an algorithm to check whether given integer value is PRIMEor
It abstract NOT.
form ofa program. It consists of English like statements which perform the
specific operations. It is defined for an algorithm. It does not use any graphical 4. Draw the fowchart to find roots ofQuadratic equation ax+ bxt c=0
representation. In pseudo code, the program is represented in terms of words
and phrases, but the syntax of program is not strictly followed. Note Practice more related Algorithms and Flowchars
Advantages: *
Easyto read, Easy to understand,* Easy to modify
Example: Write a pseudo code to perfom the basic arithmetic operations.
Read nl, n2
Sum=nl +n2

Diff=nl -n2

Mult =nl* n2
Quot nl/n2

Print sum, dif, mult, quot

End

You might also like