0% found this document useful (0 votes)
11 views12 pages

3 Flow Charts (E-Next - In)

The document introduces flowcharts as a symbolic representation of problem-solving steps essential for programming and systems analysis. It categorizes flowcharts into system and program flowcharts, describes standard symbols used, and outlines their advantages in communication, planning, and documentation. Additionally, it covers constants and variables, detailing their types and roles in flowcharting, and provides an example to illustrate flowcharting concepts.

Uploaded by

atulxcx
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)
11 views12 pages

3 Flow Charts (E-Next - In)

The document introduces flowcharts as a symbolic representation of problem-solving steps essential for programming and systems analysis. It categorizes flowcharts into system and program flowcharts, describes standard symbols used, and outlines their advantages in communication, planning, and documentation. Additionally, it covers constants and variables, detailing their types and roles in flowcharting, and provides an example to illustrate flowcharting concepts.

Uploaded by

atulxcx
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/ 12

Flowcharts

Elementary Concepts
INTRODUCTION
Before solving a problem with the help of a computer, it is essential to plan the solution in a step by step
manner. Such a planning is represented symbolically with the help of the so-called flowchart. It is an important
tool of systems analysts and programmers for tracing the information flow and logical sequence in data
processing. Logic is the essence of a flowchart.
A flowchart is the symbolic representation of the step by step solution of a given problem, and it
indicates the flow of the entire process, the sequence of data input, operations, computations, decisions,
results and other relevant information, pertaining to a particular problem. A flowchart helps us in the
complete understanding of the logical structure of a complicated problem and in documenting the method
used. As one studies the subsequence chapter, it would be seen that a flowchart is a very convenient method
of organizing the logical steps and deciding what, when and how to proceed with the various processes.
Flowcharts can be drawn for simple as well as complex operations and are possible even in a non-
computerised environment. Trial and error should be avoided as the computer time is precious. The logic
should be depicted in the flowchart. Computerization of data without a flowchart is like constructing a building
without proper design and detailed drawings. KINDS OF FLOWCHARTS
Flowcharts can be broadly classified into two categories
( 1) System Flowcharts: These are used by Systems Analysts to describe the data flow and operations for
a data processing cycle. A system flowchart defines the broad processing in the organizations, showing the
origin of data, filling structure, processing to be performed, output that is to be generated and necessity of any
off-line operation. This book does not cover this aspect of System flowcharts.
(2) Program Flowcharts : These are normally used by the programmers to describe the sequence of
operations and decisions for a particular problem. A program flowchart plans the program structure and also
serves the purpose of documentation for a program which is to be retained and used at a later data by either
the original programmer or others. The reader is recommended to prepare a detailed program flowchart for
the solution of a given problem which should include the basic steps, expanded to a level, from which
instructions can be directly coded.
The subsequent chapters of this book illustrate program flowcharts for various types of problems. An
attempt has been made to draw these flowcharts so as to be suitable for direct conversion into any computer
language like COBOL, BASIC, FORTRAN, PASCAL, PL/1 etc., just by following the syntax rules of that languages.
SYMBOLS USED IN FLOWCHARTS
The flowchart being a symbolic representation,* standard symbols have been evolved. These symbols
are used to represent the sequence of operations and the flow of data and the documents required for
programming and systems

PRE-DEFINED
TERMINAL POINT (START/STOP) PROCESS
PROCESS

FLOW-LINE
(DIRECTION)

INPUT/OUTPUT CONNECTOR COMMET


ANNOTATION

DECISION

DOCUMENT
VISUAL DISPLAY (PRINT-OUT)

Join our Telegram Group - https://t.me/EnextCommunity


Fig. 1 . Flowcharting symbol
analysis. Symbol size may be varied, but the shape should be immediately recognizable. Flow should be
normally from top to bottom, left to right. The commonly used symbols are shown in Fig. 1 .
The oval shaped symbol indicates the terminal oolnt, i.e., the beginning or end of a flowchart.
The parallelogram symbol is used for input/output of data or information from/to any device, i.e., it
indicates the operation of reading and writing.
A diamond shaped symbol is used to indicate' decisions (questions) and consequently the branch points
or the paths to be followed based on the result of a question. As an example.

No Yes
P=Q

This will first evaluate the condition P = Q. If P is equal to Q then the flow will go along the path
indicated by "YES" But if P is more than Q or less than Q (i.e. not equal to Q) then the flow goes along the path
indicated by "NO".
A rectangle symbol indicates any processing, computation and arithmetic or replacement (assignment)
operations.
A connector symbol ( a small circle) is used to connect the various portions of a flowchart. This is
normally used when the flowchart is split between various pages. A number/alphabetic character may be
written inside the circle. The circles, with same character inside them, represent the same point i.e. these are
to be joined together.
The annotation symbol is used to indicate the comments/remarks on the contents of a procedure in
order to clarify some point of the flowchart.
The document symbol is used to show any input data that is received on paper (like vouchers etc.) or any
report generated as a result of a process. In this book this symbol is used to indicate any result that is printed
out i.e., for all the outputs.
The predefined process symbol is used to show a procedure that has been already defined by another
flowchart. A reference to the appropriate flowchart is written, inside such a symbol. It actually indicates a
number of processing steps whose details is not required at this point.
The arrow symbol is used for flowchart direction and to connect the various flowchart symbols.
The visual display symbol is used to denote any output that is obtained on screen/console. This is
normally used in query programs.

ADVANTAGES OF FLOWCHARTS
The basic concepts associated with flowcharting has been presented in this chapter. Though the
flowcharts have been mostly used to help the programmer develop the program logic and to serve as
documentation for a completed program, but its advantages are many, which may be summarized as follows :
I. It is a convenient method of communication.
II. It indicates very clearly just what is being done, where as a program has logical complexities.
III. It is a key to correct programming.
IV. It is an important tool for planning and designing a new system
V. It clearly indicates the role played at each level.
VI. It saves the inconveniences in future and serves the purpose of documentation for a system.
VII. It provides an overview of the system and also demonstrates the relationship between various steps.
VIII. It facilitates trouble shooting.
IX. It promotes logical accuracy.
X. It makes sure that no logical path is left incomplete without any action being taken.

AN EXAMPLE
Let us illustrate the flowcharting concepts with an example where we want to draw a flowchart for the
following problem:

Join our Telegram Group - https://t.me/EnextCommunity


Jack and Kim have ten coins each. Hary throws a six-faced dice and at each throw there are two
possibilities
(i) the outcome is odd i.e. 1, 3 or 5.
(ii) the outcome is even i.e. 2, 4 or 6.
It is agreed upon that Jack will give a coin to Kim even/time whenever the outcome is odd i.e., possibility
ft) occurs, and Kim gives a coin to jack whenever possibility (ii) occurs. The game goes on till one or the other
has no coin left.
The problem can be formulated in the following steps:
1.Start
2. Give each player (Jack and kirn) 10 coins
3. Let Hary throw the dice.
4. Is the outcome odd ?
(a) Yes : Jack gives Kim his coin.
Go to step 5
(b) No : Kim gives Jack his coin. Go to step 6

5. Is Jack broke ?
(a) Yes : Kim wins. Go to step 7
(b) No : Go to step 3.
6. Is Kim broke ?
(a) Yes : Jack wins.. Go to step 7
(b) No : Go to step 3.
7. Stop.

The formulation can be represented in a flowchart from as illustrated in Fig. 2

START

GIVE 10 COINS TO
JACK AND KIM

ASK HARY TO
THROW THE DICE

IS THE
OUTCOME
ODD

JACK GIVES KIM


KIM GIVES JACK
HIS COIN
HIS COIN

IS JACK
NO IS KIM NO
BROKE
BROKE

YES YES

JACK WINS
KIM WINS
STOP

Join our Telegram Group - https://t.me/EnextCommunity


CONSTANTS AND VARIABLES
Let us consider the expression 4x + 3y + 9. Here x and y can assume any value but 4, 3 and 9 have fixed
values. Here x and y are the names assigned to different objects to be manipulated in the expression (or given
problem). The objects or the quantities whose value cannot be changed in a problem are termed as
CONSTANTS. The above expression contains 4, 3 and 9 as constants. On the other hand the quantities whose
value may change are called VARIABLES. In the above expression, x and y are variables. Variables are also
called IDENTIFIERS, as they identify or denote some objects.
CONSTANTS
A flowchart represents the set of instructions for manipulating "data". This data may consist entirely of
numbers (numeric) or may be non-numeric. A numeric constant consists of any digit 0 to 9 and a decimal
point. The numeric constant (number) may be positive or negative. Numbers like 45, -19, 78, -613 or 23.26183
are all "constants". These numbers cannot be changed within a flowchart. If the numeric constant, is positive,
then the plus sign may be omitted or it may be placed before the constant. For negative constants, the minus
sign is placed preceding the number. No special character, like comma etc., is specified in the constant.
Some valid numeric constants are : 9365,-213, 18.893,-7.23,-0.0034, 33 etc. Some invalid numeric constants
are : 458 - [The sign should precede the number] 3,15,468 [No comma should appear within a constant] - +
45.72.3 [Only one sign and only one decimal point is allowed]
A non-numeric constant (usually termed as String Constant) consists of a sequence of characters which
may be alphabetic, numeric, blank, operation and relation symbol or special characters. Few examples of
string constant are - "RKJ", "BOOK", "LUCKNOW" etc.
VARIABLES
While developing a flowchart we need to assign a name to the various items to be manipulated in the
flowchart. The name of the variable is a sequence of characters (the first character is alphabetic and the rest
could be any letter or digit) and refers to the memory location where the value of variable is stored. Thus if we
write R = 12, then we are in a way telling the machine (computer) to reserve a memory location which would
be named R and to store the constant 12 at that location. As far as the name of the variable is concerned, it
could be of any length. The restriction on the length is a language-dependent feature. For example, FORTRAN
does not allow variable name to be more than 6 characters, whereas COBOL allows upto 31 characters long
variable names. No special character should appear in the name of a variable
Examples of valid variable names are:
PI, A3, Bl, FORCE, QUANTITY, MR(5) A(l). Here the last two variables are subscripted
TYPES OF VARIABLES
A variable used in a flowchart can assume any value from a set of various items. For example the variable
NUMSTU may denote the number of students in a class. It can assume a value from the set of integers. The
variable CLOTHLEN, that may denote the length of a piece of cloth in metres can assume a value from the set
of real numbers. The type of variable is said to be the same as the type of the value that it assumes. The types
of variable is said to be the same as the type of the value that it assumes. The types of variables are described
below:
INTEGER VARIABLES
This type of variables can assume any value from the set of integers (positive whole numbers, negative
whole numbers and zero). The range of integers is finite and depends upon the computer configuration. For
example in most of the 8 bit computer systems, the integer variables have values between-32768 to 32767
(both inclusive). The result of any operation that is performed on integer variables will normally be another
integer and care must be taken that the result is a valid integer within the acceptable range The basic
arithmetic operators (addition, subtraction, multiplication, division and exponentiation can operate on integer
variables. The meaning of these operators is explained by the following examples :
Consider two integer variables Aand B with values 10 and 3 respectively then
A+B=13; A - B = 7; A * B = 30;
A/B = 3 (Note that integer divided by integer is integer)
A**B = 10000
REAL VARIABLES
Real variables can assume any real value (whole numbers and fractions, both positive and negative. Thus,
9.2, -18.99,3.14159 are all possible values of real variables. The range of real variables also depends upon the

Join our Telegram Group - https://t.me/EnextCommunity


computer configuration. A typical computer may allow real variables to assume values in the range ± 2.99 x
38
10 .
The five arithmetic operators can be used with real variables and following examples illustrate such
computation.
Let Aand B be two real variables with value 4 2 and 3.0 then
A + B = 7.2; A-B = 1.2; A*B=12.6;
A/B = 1.4 A **B = 74.088
STRING VARIABLES
These are non-numeric variables and hold symbolic characters rather than numbers. Thus the string
variables can assume a sequence of characters which may be numeric, alphabetic, blank, punctuation, special
symbols or a combination of these. These variables are not used in Computations but some computer
languages allow addition of strings, which is basically their concatenation. If A and B are two string variables
with values 'RUC and CRB' the operation A + B will lead to another string whose value will be RUCCRB'.
Similarly 'ABC + 'XYZ' will lead to ABCXYZ'. String variables are used to denote quantities like the names of
persons, addresses, items, names of months and days etc.
LOGICAL VARIABLES (BOOLEAN VARIABLES)
These are also non-numeric variables and can only assume values from the set of Boolean numbers i.e.
TRUE and FALSE. These are achieved as a result of comparison of expressions. The logical operators (AND, OR,
NOT, XOR, NAND and NOR) and the relational operators, < >, <=, >= = < >) can be used with Boolean variables.
Consider the logical (Boolean) variables P, Q, R, S whose values are
P 7 is greater than 3
Q (7 < 3) AND (5 > 2)
R [(A>C)OR(D<B)]AND(A<>B)
S (5<>4)OR(8>9)
Here the values of the logical variables P, Q and S are TRUE, FALSE and TRUE respectively. The value of
the variable R will depend upon the values of numeric variables A, B, C and D. The logical variables are not
used in any computation but they may be used in decision boxes or in conditional statements of a program.

Flowcharting Simple Computations


INTRODUCTION
In an attempt to solve problems on a computer, one has to express the steps for the solution in terms of
simple conceptual instructions and operations and then obtain the results. There may be a number of ways to
solve a given problems and the solution-methods may vary from person to person, depending on one's logic.
But the basic steps would constitute:
(i) Formulating the problem and deciding the input data,
if any.
(ii) Identifying the various steps of computation that
are must for the solution.
(iii) Identifying the points of decision i.e., under what circumstances a particular operation is to be
performed and when it is not to be performed.
(iv) Knowing the expected results and when to obtain the output.
Besides these, the programmer has to decide the various type of variables that should be used to solve
the problem. This chapter introduces these concepts with a number of examples. The reader is expected to
solve the problems given as exercises at the end of this chapter to understand the techniques of flowcharting.
ILLUSTRATING EXAMPLES
Example 1. (Greater of two numbers).
Draw a flowchart to find out the greater of given two numbers.
Let Aand B be the given two numbers The output will beeitherAorB, depending upon which is greater of
these two. We proceed with the following steps in the solution :
(i) Read the values of A and B.

Join our Telegram Group - https://t.me/EnextCommunity


(ii) Compare these values to determine if A is greater of B.
(iii) If A is greater than B, then output the value of A otherwise output the value of B. (iv) Stop.
These steps are pictorially shown as a flowchart in
Fig. 3.

Start

Fig. 3. Finding greater of two numbers.


The first block in the flowchart, labelled START, indicates the beginning of the procedure. The oval-
shaped symbol represents the START operation. The next block is to read the values of two numbers A and B
and this is represented by a parallelogram. A lone with an arrow connects any two blocks in the flowchart. The
read block can be interpreted as 'Take the numbers found in memory boxes with labels A and B". We will
assume that the values of A and B are respectively 15 and 28.
Following the arrows, we reach the diamond shaped box in which is written "Is A > B?". This symbol
shows a comparison or query. This query normally has two outcomes, YES or NO. If A is greater than B, i.e., less
than or equal to B, we follow the line labelled "NO".
With the assumed values of Aand B (i.e., 15 and 28) the query A > B leads to '' NO" condition and we
reach th print block stating "Print B". It is interpreted as "Take th values of memory location with label B and
Print it". Final the STOP box is encountered and the processing halts.
The reader is urged to follow the flowchart with a number of other values of A and B and convince
himself that the flowchart is correct.
Example 2. (One's complement).
Given a single digit binary number. It is required to computer its 1 's complement.
Recall that 1 's complement of a given binary number is obtained by flipping each digit, i.e., converting
each 0 to 1 and each 1 to 0. It may also be obtained by subtracting each digit from 1.
Fig. 4 illustrates one possible solution of this problem. The given number (assumed to be stored in the
variable BN) is accepted from any input device, and this step is represented by a parallelogram. Next step
checks whether this number BN is 1 or not. If it is 1 then we proceed along the ' 'YES" branch of the decision
box and assigns 0 to its 1's complement (The variable OC has been assumed for one's complement). On the
other hand, if BN is not 1 (of course then it is 0, as binary number has only two possibilities 0 and 1) then the
1's complement OC is assigned 1. Finally the value of OC (which is 0 if BN is 1 and 1 if BN is 0) is printed and the
processing stops.
START

READ BN

OC=1 BN=1 OC=0

PRINT OC

STOP

Join our Telegram Group - https://t.me/EnextCommunity


Fig. 4(a) Finding one's complement of a binary numbers.

START

READ BN

OC=1-BN

PRINT OC

STOP
Fig.4(b) Alternate Solution

An alternate solution of this problem appear in Fig. 4(b). Here a structured approach has been followed
and the use of decision box is eliminated. The 1 's complement OC is obtained by subtracting the given binary
number BN from 1. If the input value of BN is 1 then OC = 1-1=0 and if the input value of BN is o then OC = 1 - 0
= 1 which is the correct value of 1 's complement.
Example 3. (Celcius to Fahrenheit).
Draw a flowchart to convert the temperature specified in degree Celcius to Fahrenheit. The desired
conversion is based on the formula.
F = (9 * C) / 5 + 32
where C specifies the temperature in degree Celcius and F is its corresponding value in Fahrenheit.
We first read the value of the temperature in degree Celcius. Let the variable C denote this. The reading
operation is specified by the parallelogram shaped input-box in Fig. Use the formula for conversion and the
rectangular box represents this computation The result is stored in the memory location with label F, Which is
finally printed and the processing ends.

F = (9 * C) / 5 + 32

Let us assume that the memory location with label C Contains a value 25. Then F = (9 * C) / 5 + 32 results
in a value 77 which is the corresponding Fahrenheit equivalent of 25 celcius degrees.
Example 4. Draw a flowchart to generate and print first N positive integers 1, 2, 3, , N.
Let us-assume a variable (say A) to denote the positive integer generated at any instant. The initial value of this
variable should be assigned 1. Note that any positive integer can be obtained by adding 1 to its predecessor.
Hence, it is a repeating process. We will always and 1 to the present value of A and the next integer will be A +
1. Which is the successor of the previous value of A. As this next integer is to be used again in order to
calculate its successor, we assign A + 1 to A. The entire process will form a loop (refer section 3) which will
terminate as soon as the value of A reaches N, The complete formulation of the problem is as below and Fig. 6
is its flowchart representation.

Join our Telegram Group - https://t.me/EnextCommunity


Start

YES

Stop

1. Start (oval-shaped box). Fig 6. Generating first N positive integers.

2. Input the value of N, i.e., the number of Integers to be generated (parallelogram-shaped box).
3. Assign 1 to variable A (rectangular-box).
4. Print A (Print-box).
5. Is the value of A equal to the value of N ? (Decision-box)

(a) Yes : Go to step 6.


(b) No : Increase A by 1. Go to step 4.
6. Stop (oval-shaped box).
Example 5. (Sum of first N positive integers).
It is desired to sum the sequence of numbers generated in Example 4 i.e. add N terms of the series
S = 1 + 2 + 3 + 4 + 5+6+ .......................... + N
We assume a variable SUM to denote the net total of the specified number of terms N. Assign a value
zero to SUM in the beginning. Generate the numbers according to Example 4 and go on adding each generated
number to SUM. This can be achieved by assigning SUM + A to SUM.
The importance of assigning zero to SUM lies in the fact that addition of any number to zero will result in
the same number, so that the overall sum is not altered.
The addition of the generated numberA to SUM results in a loop (refer section 4.3). Its processing
continues till A reaches N. At the terminating condition the variable SUM will contain the total of the desired N
terms which is to be printed.

Join our Telegram Group - https://t.me/EnextCommunity


START

STOP

Fig 7. Adding first N


Fig. 7. Illustrates the completenumbers.
flowchart. After the START box, the value of N i.e., number of terms to be
added is read. Let us assume N = 5. Then the rectangular box indicates the assignment of zero to variable SUM.
The next box assigns 1 to A as done in Example 4. First for A = 1. The assignment SUM = SUM + A yields SUM =
0 + 1 = 1.
NowA(= 1) is compared with N (= 5) which is not true and the path indicated by "NO" of the decision box
is followed, where the assignment A = A+ 1 is encountered This makes the value of A as 1 + 1 = 2 (the next
term).
Now forA= 2, this yields SUM = 1 + 2 = 3. Again A is compared with N and in "NO" case, it is increased by 1.

A = 3 will yield SUM = 3 + 3 = 6

Similarly A = 4 will yield SUM = 6 + 4 = 10

Finally A = 5 will yield SUM = 10 + 5 = 15


At this stage A is equal to N, therefore, the decision box will lead to "YES" branch, where the PRINT BOX is
encountered. The value of SUM (= 15) is printed and the processing stops.
Example 6. Study the flow chart of fig carefully and find out the sequence of numbers that it generates
This flowchart is assigning zero to variable NUM and one to the variable I. After these assignments, the
rectangular box stating NUM = NUM + I is encountered Thus:
First for 1 = 1, this yields NUM = 0 + 1 = 1

START

NUM=0

NUM=NUM+1

PRINT NUM

I=I+2 I=11
NO
YES
FIG 8
STOP

Join our Telegram Group - https://t.me/EnextCommunity


Now I is compared with 11 in the decision box and since it is false, the box leads to "NO" branch where I is
increased by 2

then for i = 3. This yields NUM = 1 + 3 = 4


then for i = 5. This yields NUM = 4 + 5 = 9
then for i = 7 This yields NUM = 9 + 7 = 16
then for i = 9 This yields NUM = 16+ 9 = 25
finally for i = 11 This yields NUM = 25+ 11 =36
As soon as I reaches 11, the processing terminates.
Thus the sequence of numbers generated is 1, 4, 9, 16, 25, 36.
Example 7. (Sum of squares of first N positive integers) Draw a flowchart to add N terms of the series :
2
S = 1 + 4 + 9 + 16 + 25 + 36 +............. + N .
Note that in this series, the first term is square of 1, second term is square of 2, third terms is square of 3 and
so on. We have seen in Example 5 that the terms are 1,2,3, 4….. so the assignment SUM = SUM + A** 2.
[Note that A * A and A ** 2 leads to same result i.e., square of A]
First read the value of the number of terms N (Say 5) to be added. As usual, we assume a variable SUM
to denote the total of N terms and assign a value zero to it. Now 1 is assigned to the variable A. The major
processing is done in the next rectangular box where
SUM = SUM+A*A
is specified. Refer fig. 8 for the detailed flowchart. At this stage SUM assumes a value 0 + 1*1 = 1.
Now A is compared with N, which is false. Therefore A is increased by 1. The process of assigning
SUM = SUM + A*A to SUM is repeated.

Join our Telegram Group - https://t.me/EnextCommunity


Fig 9. Adding N terms of 1 + 4 + 9 + 16 + .....
For A = 2, SUM becomes 1 + 2 * 2 = 5.
Then for A= 3, SUM becomes 5 + 3 * 3 = 14
Then for A = 4, SUM becomes 14 + 4 * 4 = 30
Finally for A = 5, SUM becomes 30 + 5 * 5 = 55
This value of SUM (if number of terms are 5) will finally be printed. The processing can be continued in a
similar fashion if the value of the number of terms (N) is more and will halt only when the value of A becomes
equal to N.

Example 8. (Factorial of a number) The factorial of a number is the product of first N positive integers. It is
denoted by N !
START

READ N

FACT=1

I=2

FACT=FACT*I

NO

I=I+2 I=N

YES
PRINT FACT

STOP

Fig 10. Factorial of a number


Thus N! = 1 * 2 * 3 * 4 * 5 ..................... * N.
Let the variable FACT denote the factorial of the given number N, which is to be assigned 1 in the
beginning. This is done because FACT is to be further multiplied by 2, 3,4, …….and any multiplication by 1 does
not alter the result.
Note that while adding the terms, we initialize the concerned variable to zero whereas while multiplying
the terms, we initialize the variable to one.
In the flowchart of Fig 8 the variable I serves the purpose of a "counter" (refer to Section 3) which is
assigned a value 2 in the beginning. This yields
FACT = FACT * I = 2 * 1 = 2
Now I is increased to 3 so that
FACT = FACT * I = 2 * 3 = 6
Again I is increased by 1 so that
FACT = 6 * 4 = 24
This continues till I reaches the value N. The counter I is initialized with a value of 2 instead of 1 at the start.
The flowchart will work well even if it is initialized to 1 in the beginning. Assigning a value 2 in the beginning
saves one step, without altering the result. The reader is urged to reason put this logic.

Join our Telegram Group - https://t.me/EnextCommunity


The reader is also advised to go through the flowchart carefully and verify.
5 ! = 120; 8 ! = 40320; 10 ! = 3628800
Example 9. (Area of a triangle)
Given three sides of a triangle a, b and c. It is required to compute the area of the triangle.
We may use the formula :

AREA = √s(s-a)(s-b)(s-c)
wheres s = (a + b + c)/2
for the calculation of the area

START

READ A,B,C

S=(A+B+C)/2

AREA=√S(S-A)(S-B)(S-C)

PRINT AREA

STOP

Fig 11. Area of a Traingle, Given its Sides.


This problem is just the application of a simple formula. The values of the three sides of the triangle are
read and stored in the variables A, B and C.
The semi-perimeter S is computed which is illustrated by a rectangular box. Finally this value of S is used
to calculate the desired area. Refer Fig. 4.11 for the flowchart representation.
The important point to note here is that the square root of a quantity (s - a) (s - b) (s - c) has been
calculated in this problem and the symbol of has been used for this purpose. Remember that such a symbol is
not available on the usual key-boards.
The various computer-languages allow pre-defined functions (namely SORT or so) for this purpose. Using
this function, the assignment

AREA = √s (s - a) (s - b) (s - c) will change to


AREA = SORT ( S * (S - A) * (S - B) * (S - C) ) and will compute the square root of the quantity s ( s -a) (s - b) (s -
c).

Join our Telegram Group - https://t.me/EnextCommunity

You might also like