0% found this document useful (0 votes)
10 views

Script 1 1

The document discusses flowcharts and their use in problem solving and programming. It explains that flowcharts can help represent solutions to problems visually and illustrate programming logic and structures. The document also outlines some basic data types in C like int, float, char, and others.

Uploaded by

san
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Script 1 1

The document discusses flowcharts and their use in problem solving and programming. It explains that flowcharts can help represent solutions to problems visually and illustrate programming logic and structures. The document also outlines some basic data types in C like int, float, char, and others.

Uploaded by

san
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

THE ART OF PROGRAMMIMG METHODOLOGY

Module – 1: PROBLEM SOLVING USING FLOWCHART

Dear friends,
In Today’s discussion we will cover the very beginning and
general concepts related with problem solving and programming.
Algorithms and Flowcharts are the most effective tools, used for both
problem solving and programming. In this module we will discuss
about the problem solving approach based on flowchart.
Flowchart for structured programing
Structured programming is a programming paradigm aimed at
improving the clarity, quality, and development time of a computer
program by making extensive use of subroutines, block structures
and loops. Before going to jump into the structured programming
terminology we need to find an optimal and clear solution for the
problem. One of the best way to represent your solution of a
particular problem is a flowchart.

A flowchart is a type of diagram that represents an algorithm,


work flow or process. It shows the steps as boxes of various kinds,
and their order by connecting them with arrows. This diagrammatic
representation illustrates a solution model to a given problem.
Flowcharts are used in analyzing, designing, documenting or
managing a process or program in various fields.

The major structures included in a structured programming


paradigm is sequence, decision, loop and cases. Using flowchart, we
can simulate all these concepts of a structured programming. Also
this image level representation makes easier understanding of given
problem. .

A good flowchart is like a snapshot of a program which tells


you, at a glance, where the information originates, how it handles the
information and produces the desired outputs. A flowchart should be
designed in such a way that the users are able to follow it easily. It
should have sufficient details providing an accurate picture of what’s
going on in the flowchart. Flowcharts should be read from top to
bottom and left to right.

A flowchart usually have a plenty of white spaces without being


crowded on the page. A flowchart should have a title based on what it
represents. Ex: naming a flowchart as 'flowchart of addition of two

Page - 1
numbers'. Select appropriate symbols while designing the flowchart
(the symbols are discussed later in this section).

The advantage of designing a flowchart are:-

1. Conveys Better Meaning

Since a flowchart is a pictorial representation of a program, it is easier


for a programmer to understand and explain the logic of the program
to some other programmer.

2. Analyses the Problem Effectively


A macro flowchart that charts the main line of logic of a software
system becomes a system model that can be broken down into
detailed parts for study and further analysis of the system.

3. Effective Joining of a Part of a System


A group of programmers are normally associated with the design of
large software systems. Each programmer is responsible for
designing only a part of the entire system. So initially, if each
programmer draws a flowchart for his part of design, the flow charts
of all the programmers can be placed together to visualize the overall
system design. Any problem in linking the various parts of the system
can be easily detected at this stage and the design can be
accordingly modified. Flowcharts can thus be used as working
models in the design of new programs and software systems

4. Efficient Coding
Once a flowchart is ready, programmers find it very easy to write the
concerned program because the flowchart acts as a road map for
them. It guides them in proceeding from the starting point of the
program to the final point ensuring that no steps are omitted. The
ultimate result is an error free program developed at a faster rate.

5. Systematic Debugging
Even after taking full care in program design, some errors may
remain in the program because the designer might have never
thought about a particular case. These errors are detected only when
we start executing the program on a computer. Such type of program
errors are called bugs and the process of removing these errors is
known as debugging. A flowchart is very helpful in detecting, locating,
and removing mistakes (bugs) in a program in a systematic manner.

6. Systematic Testing
Testing is the process of confirming whether a program will
successfully do all the jobs for which it has been designed under the
specified constraints. For testing a program, different sets of data are

Page - 2
fed as input to that program to test the different paths in the program
logic.

Flow chart types:


The graphical representation called a flowchart is used to
design the flow of information from the start of a program till its end.
Flowcharts are classified based on their purpose as system
flowcharts and program flowcharts. A system flowchart gives a big
picture look of the system.
A program flowchart shows the logical association with the
computer program.

Variables and Data names

A variable is an entity that may vary during program execution.


For example let ‘x’ be an integer variable which can store a value that
can be changed during the execution of a program.

Let x=5. After adding an integer value say ‘2’, the value of x will be
varied to 7.

Variable names are names given to locations in memory.


These locations can contain integer, real or character constants.
Data names (data type) refers to the type of data that may be
stored in a variable. In programming a data name or data type is a set
of values and predefined operations to manipulate these values.
Some examples of data names can be alphabet indicating a set of
characters, or names indicating names a sequence of characters, or
ages indicating integer numbers, or price indicating real numbers, or
salaries, calories, all kinds of measures and so on.
Each data has its own specifics; where one type of data is
good for a given situation it could not work well in another. So it is
better to distinguish data based on their characteristics, advantages
and disadvantages. For this we should initially understand their
parameters including purpose, size, range, sign, precision, etc. The
purpose may be to store an integer or real or character or a boolean
value. Varying on the application different data requires different size
to be stored on. Usually we measure it in bytes or shortly “B”.
Depending on the size the types could work with numbers from
different ranges. If you try to store number, which is out of the range,
an overflow will occur and data will be lost. It is good to optimize your
programs. If you don’t need to use a big size(range) type, you should
use the smaller(shorter) version. Of course if you are unsure if the
type is big enough – take the bigger range. It is better to take several
bytes more than lose information, because of an overflow. When
signed, the type can represent both positive and negative numbers.
Unsigned types work only with positive numbers and they can hold

Page - 3
numbers twice bigger than signed. This applies to numeric types and
could depend on the programming language.
Coming to C language, it has the following basic built-in data types.
 in
 float
 double
 char
int represents Integer ; It holds integer values.
For example:
int a;
Here “a” is the variable that holds integer type values.
Char represents character, holding one character.
Eg: char c;
Char data type can also be used to initialize a string as an array of
characters.
Eg: char name[10];
Here, name is declared as a string that represents an array which can
hold a maximum of 10 character elements.
Float holds single precision floating values.
Eg: float
Double holds double precision floating values.
Apart from these built in data types, C also supports user defined
data types which will be discussed in the later sections.

Programming Statements

Programming Statements are the commands given to the


computer that instructs the computer to do a specific action, such as
display to the screen, or collect input. A computer program is made up
of a series of statements.

Label statements: A statement can be preceded by a label.


For example,
goto label:
Here label shows the target
Compound Statements: It groups multiple statements into a single
statement. It consists of multiple statements and declarations
enclosed within brace ie; ({ and }).
For example
{
pi=3.14;
area=pi*radius*radius;

Expression Statements: An expression statement consists of an


optional expression followed by a semicolon (;). If the expression is

Page - 4
present, the statement may have a value. If no expression is present,
the statement is often called the null statement.
Selection Statements: There are 3 types of selection statements
(i)Simple if
Syntax:
If (expression)
statement
In this type of if-statement, the statement will be executed only when
the expression is non-zero or true.
(ii) if else
Syntax:
If (expression)
statement 1;
else
statement 2;
In this type of if-statement, the statement 1 will be executed if the ex-
pression is non-zero; otherwise, the statement 2 will be executed.
(iii) Switch statements
Switch statements are also a type of selection statement. They have
the format of
switch (expression)
{
case 1:
statement 1;
break;
case 2:
statement 2;
break;
default:
statement 3 ;
break;
}
Iteration Statements: C has three kinds of iteration statements.
(i)The while statement.
While statement is of the form,
While(Control expression)
{

Page - 5
Statements
}
The statements inside the brackets run repeatedly until the control ex-
pression evaluates to zero. Otherwise it m
ay not run at all.
(ii) do while
do-while statement is of the form
do
{
Statements;
} while(control expression);
Here the control expression is evaluated at the end of the loop in-
stead of the beginning and consequently the statements inside the
brackets must execute at least once.
(iii) for
For statement of the form
for( initialization; condition;
increment/decrement )
{
Statement 1;
}
* The initialization step is executed first, and only once. This
step allows you to declare and initialize any loop control variables.
* Condition is evaluated. If it is true, the statement1 (body of
the loop) is executed. If it is false it does not execute and the flow
of control jumps to the next statement just after the 'for' loop.
* After the body of the 'for' loop executes, the flow of control
jumps back up to the increment statement. This statement allows
you to update any loop control variables.
Flowchart Symbols

Page - 6
A flowchart uses predefined symbols. The following table
shows the flow chart symbols such as terminal symbol, I/O process,
decision symbol etc.

Symbol Name
Start / end

Arrow

Input/ output

Process

Decision

Connector

The Loop symbol

Comment symbol

connectors are used to show the direction of flow of control.


1. Terminal symbol indicates start or end of a flow chart. It is an
oval shaped symbol that represents start or end point. Ideally a
terminal symbol is used to indicates ”start”, “begin” or “end” of
a flowchart. In addition, if the program logic calls for a pause in
the program, that also is indicated with a terminal symbol. A
pause is normally used in the program logic under some error
conditions or in case the forms had to be changed in the com-
puter’s line printer during the processing of that program

Page - 7
2. Input/output symbol: input/ output symbol is a parallelogram
that represents input or output to a program. If there is a pro-
gram instruction to input data from a disk, tape, card reader,
terminal, or any other type of input device, that step will be in-
dicated in the flowchart with an input/output symbol. Similarly,
all output instructions, whether it is output on a printer, mag-
netic tape, magnetic disk, terminal screen, or any output de-
vice, are indicated in the flowchart with an input/output symbol.
3. Process symbol: A rectangle is used to represents a process,
action or an operation, which mostly includes some verbs. This
symbol represents arithmetic and data movement instructions.
Thus, all arithmetic processes such as adding, subtracting,
multiplying and dividing are shown by a processing symbol.
The logical process of moving data from one location of the
main memory to another is also denoted by this symbol. When
more than one arithmetic and data movement instructions are
to be executed consecutively, they are normally placed in the
same processing box and they are assumed to be executed in
the order of their appearance. Eg: calculate sum (sum=A+B)
etc.
4. Decision symbol: A diamond indicates a decision used to rep-
resent a question in a flowchart. Decision symbols have a sin-
gle point of entry, but may have multiple exits. The exit is deter-
mined by the answer to the question and separated by differ-
ent arrows coming out of the diamond. Ex: there can be two
exits ‘yes’ and ‘no’. The condition upon which each of the pos-
sible exit paths will be executed, should be identified and all
the possible paths should be accounted for. During execution,
the appropriate path is followed depending upon the result of
the decision.
5. If a flowchart becomes very long, the flow lines start
crisscrossing at many places that causes confusion and
reduces the clarity of the flowchart. Moreover, there are
instances when a flowchart becomes too long to fit in a single
page and the use of flow lines becomes impossible. Thus,
whenever a flowchart becomes too complex that the number
and direction of flow lines is confusing or it spreads over more
than one page, it is useful to utilize the connector symbol as a

Page - 8
substitute for flow lines. This symbol represents an entry from,
or an exit to another part of the flowchart. A connector symbol
is represented by a circle and a letter or digit is placed within
the circle to indicate the link. A pair of identically labeled
connector symbols are commonly used to indicate a continued
flow when the use of a line is confusing. So two connectors
with identical labels serve the same function as a long flow
line. That is, they show an exit to some other chart section, or
they indicate an entry from another part of the chart. To
determine if a connector is used as an entry or an exit point,
we look whether if an arrow enters but does not leave a
connector, then it is an exit point and program control is
transferred to the identically labeled connector that does have
an outlet. It may be noted that connectors do not represent any
operation and their use in a flowchart is only for the sake of
convenience and clarity
6. A loop symbol indicates a sequence of commands that will
continue to repeat until a condition is satisfied.
7. Flow lines with arrowheads are used to indicate the flow of
operation, that is, the exact sequence in which the instructions
are to be executed. The normal flow of flowchart is from top to
bottom and left to right. Arrowheads are required only when the
normal top to bottom flow is not to be followed. However, as a
good practice and in order to avoid confusion, flow lines are
usually drawn with an arrowhead at the point of entry to a
symbol. Good practice also dictates that flow lines should not
cross each other and that such intersections should be
avoided whenever possible.
8. The comment symbol, also called as note symbol is used to
add an explanation or a comment, connected by a dashed line
to the relevant section of the flowchart.
The general tips to be considered while designing a Flowchart are as
follows:-
(a) First formulate the main line of logic, then incorporate the details.
(b) Maintain a consistent level of detail for a given flowchart.
(c) Do not give every detail on the flowchart. A reader who is
interested in greater details can refer to the program itself.
(d) Words in the flowchart symbols should be common statements

Page - 9
and easy to understand.
(e) Be consistent in using names and variables in the flowchart.
(f) Go from left to right and top to bottom in constructing the flowchart

1. Now we can design a simple Flowchart to find the sum of two num-
bers

The flowchart begins with the terminal symbol ‘start’. Here, there are
two variables n1 and n2. To read these values we use the input sym-
bol parallelogram. The value of sum is stored in the variable sum. The
process of finding sum is depicted in the flowchart using the rectan-
gle. The output value is represented using the parallelogram again.
This prints the value inside the variable sum. Finally the terminal sym-
bol ‘Stop’ ends the flowchart.

2. Let us go through another example of designing a flowchart to


find the largest from the three entered numbers.

Page - 10
Here, we read 3 values to the variables A, B and C. First check
whether A is greater than B. If “Yes” then check A with C. If “Yes” then
print A is the largest number. If A is not greater than B then check B
with C. If “Yes” print B is the largest number. Otherwise C is the
largest number.

Summary

Here we discuss about how to solve a problem in a systematic


way and explains the use of flow chart. . Flowchart is a pictorial or
graphical representation of a process and its purpose is to
communicate how a process works. Flowcharts play an important
role in programming of and are quite helpful in understanding the
logic of complicated and lengthy problems. Flowcharts are used in
analyzing, designing, documenting or managing a process or

Page - 11
program in various fields.
Flowcharts are generally drawn in the early stages of
formulating computer solutions. Once the flowchart is drawn, it is
easy to write the program. A good flowchart is like a snapshot of a
program which tells you, at a glance, where the information
originates, how it handles the information and produces the desired
outputs A flowchart uses predefined symbols such as terminal
symbol, I/O process, decision symbol etc.
A computer program is made up of a series of statements.
Programming Statements are the commands given to the computer
that instructs the computer to do a specific action, such as display to
the screen, or collect input. Commonly used programming statements
are label statements, compound ststements, expression statements
and iterative statements.

Assignments

 Explain flowchart and symbols.


 Draw a flow chart for checking whether the entered number is
prime or not.
 Which are selection statements? Explain with example.
 Explain about programming statements in detail.

Reference

 B. W. Kernighan and D. M. Ritchie, The C Programming


Language, Prentice-Hall, Englewood Cliffs, New Jersey,
1978.
 Greg Perry, Absolute Beginners' guide to C 2nd Edition,
SAMS publishing, A division of Prentice Hall Computer
Publishing, 201 West 103rd Street , Indianapolis, Indiana
46290. April 1994.
 Yashavant Kanetkar; Let us C, BPB Publications, New
Delhi.

Page - 12

You might also like