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

2nd Chapter

1 034 590 0751 034 590 0751 034 590 075sdsa1 034 590 0751 034 590 0751 034 590 0751 034 590 0751 034 590 0751 034 590 075

Uploaded by

axxkid69
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)
36 views

2nd Chapter

1 034 590 0751 034 590 0751 034 590 075sdsa1 034 590 0751 034 590 0751 034 590 0751 034 590 0751 034 590 0751 034 590 075

Uploaded by

axxkid69
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/ 6

Chapter#02

An Overview of “C” Language

ALGORITHM: An algorithm is the set of well –defined instruction in a sequence to


solve a program and these instructions ultimately terminate if followed.
Qualities of a good algorithm
 Inputs and outputs should be defined precisely.
 Each step in algorithm should be clear and unambiguous.
 Algorithm should be most effective among many different ways to solve a
problem.
 An algorithm shouldn’t have computer code. Instead, the algorithm should be
written in such a way that, it can be used in similar programming languages.
Algorithmic Notations
1. Algorithm Name: Each algorithm must be given a unique name for identification
2.Step Number: Each statement of the algorithm must be given a unique number for
identification e.g. 1, 2, 3. etc.
3.Variable Names: Variable names will use capital letters, as X, Y, SUM.
4. Getting Input from the User: Read is used to get input from the user.
5. Assigning Value to a Variable: ‘Set’ is used to assign value to a variable.
6. Algorithm Termination: ‘Exit’ is used to terminate the algorithm.
7.Comments: ‘[’ and ‘]’ are used for providing comments or remarks.
8.Control Transfer: Use ‘Goto Step n’ to transfer control to step n.

PSEUDOCODE
Pseudocode is an English-like way of representing the solution to a problem. The prefix
pseudo means fake; Pseudocode, therefore literally means fake code—that is, not the
code that is actually entered into the computer. When using Pseudo code to plan a
program, you can concentrate on the logic and not worry about the rules of a specific
language. It is also easy to change Pseudocode if discover a mistake in logic.
Pseudocode instruction can be considered as midway between English and high-level
languages but free from ambiguities of English language.

FLOWCHART SYMBOLS
Flowchart is a pictorial representation of logic used in a computer program. It illustrates
the major program elements and how they are logically integrated. The flowchart uses
arrows to represent the direction of the program flow and shapes to display actions. The
American National Standard Institute (ANSI) has established standard for the symbols
used in flowchart.
SYMBOLS
Terminal Symbol: (Oval)

The terminal symbol is used to indicate the beginning (START), ending (STOP) and
pauses (HALT) in the program logic flow.
Start Stop Halt

Input/output Symbol: (Parallelogram)


The input/output symbol is used to denote any type of input data or output information.

Input Marks Output Result

Process Symbol: (Rectangle)

A process symbol is used for all arithmetic and data transfer (MOVE) operations.

Avg= Sum/3

Flowlines: (Arrows)
:
Flowlines with arrowheads are used to indicate the flow of operation, that is, the exact
sequence in which the instructions are to be executed.

Decision Symbol: (Diamond)

The decision symbol is used at point where decision has to be made. It has two arrows
coming out of it usually from bottom or right point with one corresponding to yes and
other corresponding to no. the arrows should always be labelled.

Yes
If A>B

No

On-Page Connector Symbol: (Circle)

If a flowchart becomes very long, the flow lines start crossing at many places that
causes confusion and reduces understandability of the flowchart. In this situation it is
useful to utilize the connector symbol as a substitute for flow lines. An on-page
connector symbol is represented by a circle and a letter or digit is placed within the
circle to indicate the link.

Off-Page Connector Symbol:


This symbol is used to connect parts of the flowchart from one page to another.

Predefined Process Symbol:


This symbol is used to access (“perform” or “call”) a subroutine or pre-defined process.

Annotation Symbol:
It is used to add comments, explanatory notes, or clarifications; connected by dashed
line to the symbol being commented on.

Pay=BP+ Bonus BP is basic pay

CATEGORIES OF FLOWCHARTS

FLOWCHART

System flowchart Program / Logic flowchart

Micro flowchart Macro flowchart

Program Logic Flowchart:


A program/logic flowchart represents the flow of logic in a program. This flowchart is
further classified as:
 Micro - a flowchart in which only major events are shown, and
 Macro - a flowchart in which all the events (major as well as minor) are shown.

System Flowchart:
System flowchart shows the flow of data through an entire computer system.

CONTROL STRUCTURES
Control structure control how the program executes. The following three types of logic,
or flow of control are considered the basic building blocks of all program construction.
 Sequence logic
 Selection logic
 Iteration logic

Sequence
The sequence control structure is the most straightforward: One module simply follows
another in sequence.

.
.
Module 1 Module 1
Module 2
. Module 2
.

Example:

Selection
The selection control structure employs a number of conditions which lead to a selection
of one out of several alternative modules. The structures which implement this logic are
called conditional structures or IF structures. The end of IF structure is frequently
indicated by the statement “[End of IF structure]” or some equivalent statement.
This control structure has two forms: IF and IF-ELSE.
 The IF selection structure either performs an action if the condition is true or skips
the action if the condition is false. It is less complicated.

IF condition then
[Module A]
[End of IF structure] Yes
Test
Condition?

No

Module 1

 IF-ELSE selection structure performs an action if the condition is true and perform a
different action if the condition is false. It is more complicated than IF.
IF condition then
[Module A]
ELSE Yes
[Module B] Test
Condition? Module 1
[End of IF structure]

No

Module 2
Iteration
Iteration is often referred to as a loop, because the program will keep repeating the
activity until the condition becomes false. Loops simplify programming because they
enable the programmer to specify certain instructions only once to have the computer
execute them many times. WHILE, DO-WHILE, and FOR are three types of structures
involved in loops. Each type begins with a Repeat statement and is followed by a
module, called the body of the loop. The statement “(End of loop)” or some equivalent
statement frequently indicates the end of structure.

Each type of loop structure is discussed below:


(1) WHILE Loop: The WHILE loop uses a condition to control the loop at the beginning.
(2) DO-WHILE Loop: The DO-WHILE loop uses a condition to control the loop at the
end.
(3) FOR Loop: The FOR loop uses an index variable, such as K, to control the loop.

Flowchart of FOR , WHILE and DO WHILE (book page 33)

TYPES OF FLOWCHART
There are four main types of flowchart, which can be combined in different ways to
represent any given problem are given below.
Sequential Flowchart: This is the simplest type of flowchart involving no decisions,
branches or loops.
Branch (or Jump) Flowchart: In this type, one or more decision boxes are introduced,
and the action taken depends upon whether the result of the decision is yes or no.
Loop Flowchart: A loop represents a procedure which may be repeated a definite or
indefinite number of times.
Nested Loops in a Flowchart: nested loops in flowcharts are represented by loops
within loops.

ADVANTAGES OF FLOWCHART:
Communication: Flowcharts are better way of communicating the logic of a system to
all concerned or involved.
Effective analysis: With the help of flowchart, problem can be analyzed in more
effective way
Efficient Coding: The flowcharts act as a guide during the systems analysis and
program development phase.
Proper Debugging: The flowchart helps in debugging process.

DISADVANTAGES OF FLOWCHART:
Complex logic: Sometimes, the program logic is quite complicated. In that case,
flowchart becomes complex and clumsy. This will become a pain for the user.
Alterations and Modifications: If alterations are required the flowchart may require re-
drawing completely.

RULES TO DRAW FLOWCHART:


i. First understand logic and then listed down in an order.
ii. Maintain consistent level of detail for a given flowchart.
iii. Flowchart should be clear, neat and easy to follow.
iv. Each flowchart must have one and only one Start terminal.
v. The usual direction of flowchart is from top to bottom or left to right.
vi. Write within standard symbol briefly.
vii. If flowchart become complex, it’s better to use connector symbol o reduce
number of flow lines. Avoid intersection of flow lines.

You might also like