Chapter 1 C Programming
Chapter 1 C Programming
C
Programming
1.1 Introduction
1.2 Flowcharts
1.3 Types of Flowcharts
1.3.1 Types of flowchart
1.3.2 System flowcharts
1.4 Flowchart Symbols
1.5 Advantages of Flowcharts
1.6 Developing Flowcharts
1.7 Techniques
1.7.1 Flowcharts for computations
1.7.2 Flowcharts for decision making
1.7.3 Flowcharts for loops
1.7.4 Predefined process
Chapter 1 : Introduction to Flowcharting
1.1 Introduction
C
Programming
The preparation of lists of procedures and steps to obtain the result introduces
the algorithmic approach to problem solving.
The algorithm is a sequence of instructions designed in such a way that if the
instructions are executed in a specific sequence the desired results will be
obtained.
The instructions should be precise and concise and the result should be
obtained after a finite execution of steps.
This means that the algorithm should not repeat one or more instructions
infinitely.
It should terminate at some point and result in the desired output.
An algorithm should possess the following characteristics :
- Each and every instruction should be precise and clear
- Each instruction should be performed a finite number of times
- The algorithm should ultimately terminate
- When the algorithm terminates the desired result should be obtained.
Chapter 1 : Introduction to Flowcharting
1.2 Flowcharts
C
Programming
Before you start coding a program it is necessary to plan the step by step
solution to the task your program will carry out.
Such a plan can be symbolically developed using a diagram. This diagram is
then called a flowchart.
Hence a flowchart is a symbolic representation of a solution to a given task.
A flowchart can be developed for practically any job.
Flowcharting is a tool that can help us to develop and represent graphically
program logic sequence.
It also enables us to trace and detect any logical or other errors before the
programs are written.
Chapter 1 : Introduction to Flowcharting
1.3 Types of Flowcharts
C
Programming
Normally, an algorithm is expressed as a flowchart and then the flowchart is converted into
a program with the programming language.
Flowcharts are independent of the programming language being used. Hence one can fully
concentrate on the logic of the problem solving at this stage.
A large number of programmers use flowcharts to assist them in the development of
computer programs.
Once the flowchart is fully ready, the programmer then write it in the programming
language.
At this stage he need not concentrate on the logic but can give more attention to coding
each instruction in the box of the flowchart in terms of the statements of the programming
language selected.
A flowchart can thus be described as the picture of the logic to be included in the computer
program.
It is always recommended for a beginner, to draw flowcharts prior to writing programs in the
selected language. Flowcharts are very helpful during the testing of the program as well as
incorporating further modifications.
Chapter 1 : Introduction to Flowcharting
1.4 Flowchart Symbols
C
Programming
Terminal Symbol:
Every flowchart has a unique starting point and an ending point.
The flowchart begins at the start terminator and ends at the stop terminator.
The Starting Point is indicated with the word START inside the terminator
symbol.
The Ending Point is indicated with the word STOP inside the terminator symbol.
There can be only one START and one STOP terminator in you entire flowchart.
In case a program logic involves a pause, it is also indicated with the terminal
symbol.
Chapter 1 : Introduction to Flowcharting
1.4 Flowchart Symbols
C
Programming
Input/Output Symbol :
• This symbol is used to denote any input/output function in the program.
• Thus if there is any input to the program via an input device, like a keyboard,
tape, card reader etc. it will be indicated in the flowchart with the help of the
Input/Output symbol.
• Similarly, all output instructions, for output to devices like printers, plotters,
magnetic tapes, disk, monitors etc. are indicated in the Input/Output symbol.
Chapter 1 : Introduction to Flowcharting
1.4 Flowchart Symbols
C
Programming
Process Symbol :
o A process symbol is used to represent arithmetic and data movement
instructions in the flowchart.
o All arithmetic processes of addition, subtraction, multiplication and division are
indicated in the process symbol.
o The logical process of data movement form one memory location to another is
also represented in the process box.
o If there are more than one process instructions to be executed sequentially, they
can be placed in the same process box, one below the other in the sequence in
which they are to be executed.
Chapter 1 : Introduction to Flowcharting
1.4 Flowchart Symbols
C
Programming
Decision Symbol :
The decision symbol is used in a flowchart to indicate the point where a decision
is to be made and branching done upon the result of the decision to one or more
alternative paths.
The criteria for decision making is written in the decision box.
All the possible paths should be accounted for.
During execution, the appropriate path will be followed depending upon the result
of the decision.
Chapter 1 : Introduction to Flowcharting
1.4 Flowchart Symbols
C
Programming
Flowlines :
Flowlines are solid lines with arrowheads which indicate the flow of operation.
They show the exact sequence in which the instructions are to be executed.
The normal flow of the flowchart is depicted from top to bottom and left to right.
Chapter 1 : Introduction to Flowcharting
1.4 Flowchart Symbols
C
Programming
Connectors :
In situations, where the flowcharts becomes big, it may so happen that the
flowlines start crossing each other at many places causing confusion.
This will also result in making the flowchart difficult to understand. Also, the
flowchart may not fit in a single page for big programs.
Thus whenever the flowchart becomes complex and spreads over a number of
pages connectors are used.
The connector represents entry from or exit to another part of the flowchart.
A connector symbol is indicated by a circle and a letter or a digit is placed in the
circle.
This letter or digit indicates a link. A pair of such identically labelled connectors
are used to indicate a continued flow in situations where flowcharts are complex
or spread over more than one page.
Chapter 1 : Introduction to Flowcharting
1.4 Flowchart Symbols
C
Programming
Connectors :
Thus a connector indicates an exit from some section in the flowchart and an
entry into another section of the flowchart.
If an arrow enters a flowchart but does not leave it, it means that it is an exit
point in the flowchart and program control is transferred to an identically labelled
connector which has an outlet.
This connector will be connected to the further program flow from the point where
it has exited.
Connectors do not represent any operation in the flowchart.
Their use is only for the purpose of increased convenience and clarity.
Chapter 1 : Introduction to Flowcharting
1.4 Flowchart Symbols
C
Programming
Chapter 1 : Introduction to Flowcharting
1.5 Advantages of Flowcharts
C
Programming
1. A flowchart being a pictorial representation of a program, makes it easier for the programmer to
explain the logic of the program to others rather than a program
2. It shows the execution of logical steps without the syntax and language complexities of a program.
3. In real life programming situations a number of programmers are associated with the development
of a system and each programmer is assigned a specific task of the entire system.
4. Hence, each programmer can develop his own flowchart and later on all the flowcharts can be
combined for depicting the overall system.
5. Any problems related to linking of different modules can be detected at this stage itself and suitable
modifications carried out. Flowcharts can thus be used as working models in design of new software
systems.
6. Flowcharts provide a strong documentation in the overall documentation of the software system.
7. Once the flowchart is complete, it becomes very easy for programmers to write the program from the
starting point to the ending point. Since the flowchart is a detailed representation of the program
logic no step is missed during the actual program writing resulting in error free programs. Such
programs can also be developed faster.
8. A flowchart is very helpful in the process of debugging a program. The bugs can be detected and
corrected with the help of a flowchart in a systematic manner.-
Chapter 1 : Introduction to Flowcharting
1.6 Developing Flowcharts
C
Programming
Programming considerations :
Most of the programming languages have a number of loop constructs for efficiently
handling repetitive statements in a program. These include :
1. do-while loop
2. while loop
3. for loop
4. for-next loop
Chapter 1 : Introduction to Flowcharting
1.7 Techniques
C
Programming