You are on page 1of 39

Program Solving using Computer

• Creating new programs is called program


development.
• In order to develop a program, whether it is
small or complex, a special procedure to be
followed which is called as program
development life cycle(PDLC).
• It is the systematic way of developing any
quality software.
• A computer program is set of instructions
which a computer can use to solve a problem.
• To solve a problem efficiently, the programmer must
follow the following steps-
1. Problem definition and analysis
2. Program design
3. Coding
4. Compilation
5. Debugging and testing
6. Documentation
7. Implementation and maintenance
The Program Development Life Cycle
1.Problem Definition and Analysis
• The first step in developing a program is to
identify and define the problem.
• For this we analyze the problem by using the
basic steps: input, processing and output.
Input processing output
• Input is the data to solve the problem, processing
is the steps to convert input to output and output
is the result obtained after solving problem.
• During analysis, a programmer:
– talk with users to fully understand what the software
should do.
2. Program Design
• The second step of programming process is
program design.
• In this phase, the programmer must have a
proper understanding of the behavior of the
problem to be solved.
• This behavior can be described in terms of
necessary inputs and required outputs.
• Then the programmer designs a process through
different techniques like –
– Algorithm
– Flowchart
– Pseudo code
a) Algorithm
• After properly defining the problem, a detailed
step by step procedure for solving it must be
developed by the programmer called as an
algorithm.
• Algorithm are written in simple English language
to solve a particular problem.
• The algorithm is independent of any programming
language.
• A problem may have number of algorithms , the
programmer select the best algorithm that
described the solution of the problem.
The following points must be remembered
while writing an algorithm
• Each procedure should specify inputs and
outputs.
• All the variables should be properly define.
• Documentation should be there but short and
meaningful.
• Use sub-programs whenever required.
Advantages of algorithm-
• It makes a program easy to read and
understand.
• It display easy steps of processing.
• It simplify the modification and updating the
program.
The following algorithm define the solution
of sum of two numbers-
• Step 1: Start
• Step 2: Declare two numbers A and B
• Step 3: Read A & B
• Step 4: C=A+B
• Step 5: Print C
• Step 6: End
An algorithm to find largest among
two numbers
• Step 1: Start
• Step 2: Declare variable a and b
• Step 3: Read variable a and b
• Step 4: If a>b
Display a is greater

Else
Display b is greater

• Step 5: Stop
An algorithm to find largest among
three numbers
• Step 1: Start
• Step 2: Declare variable a, b and c
• Step 3: Read variable a, b and c
• Step 4: If a>b
If a>c
Display a is greater
Else
Display c is greater
Else
If b>c
Display b is greater
Else
Display c is greater
• Step 5: Stop
b) Flowchart
• Flowchart is the pictorial or graphical
representation of step by step procedure of a
problem to be solved.
• A flowchart show the actual flow of the logic
of a program.
• It is made up of symbols for various types of
operations used in the program.
Various symbols are used to draw
flowchart are-
• Terminal
• Input and Output
• Processing
• Flow lines
• Decision symbol
• Connectors
1. Terminals
• This symbol represents the beginning and end
point of the flowchart.
• The shape of terminal symbol is in oval shape.
• Used as first or last symbol in a program to
start and end the flowchart.
Start

Stop
2.Input and Output Symbol
• This symbol is used to enter data from
keyboard or to print the result on screen.

Input a , b Print c
3.Processing
• This symbol is used to represent any kind of
processing activity i.e. calculations and
arithmetic operation.

C=A+B
4. Flow Lines
• This symbol is used to show flow of data from
one point to another.
• The flow lines with arrow heads are used to
indicate the flow of operation.
• Arrow coming from one symbol and end at
another symbol.
5.Decision symbol
• This symbol is used where a decision has to be
made in selecting the different paths to be
followed.
• In this there is only one entry point and at
least two exist point.

Yes Is no
(A>B)?
6.Connectors
• This symbol is used to connect the various
position of the flow chart.
• This is normally used when the flowchart is
divided into two pages.
Limitations of Flowcharts
• It is time consuming process.
• It is difficult to draw with proper symbol.
• If little modification is required then we have
redraw the entire flowchart.
Draw a flowchart to add two numbers
Start

Input A,B

C=A+B

Print C

Stop
Draw a flowchart to find largest among two numbers
Start

Input A,B

yes Is no
(A>B)?

Print A Print B

Stop
Draw a flowchart to find largest among three numbers
Start

Input A,B
and C

YES Is YES Is NO Is YES


(A>C) (A>B) (B>C)
? ? ?
NO NO
Print B
Print A
Print C

Stop
c) Pseudo code
• It is a code which is written in English form to
solve a particular problem.
• It can have the same style and format of the
language but ignores the most punctuations.
• For example- Pseudo code for printing the bigger
out of two numbers.
{
integer a , b
read a , b
If a is greater than b
then print a
else print b
}
Advantages and Disadvantages of
Pseudo code
Advantages Disadvantages
• It is very easy to covert a • There are no standard rules to
pseudo code into follow in pseudo codes.
programming language
• In case of change in the • There is no graphical
program, pseudo code are representation.
easy to modify.
• It is very helpful tool. • It is time consuming and
lengthy.
3. Coding
• After the successful completion of second phase i.e
selection of algorithm or flowchart, it must be
converted into a form that can be used by a
computer.
• The programmer translates the steps of algorithm or
flowchart in a computer program using a language
such as C is called as Coding.
Translate into a
Algorithm/ computer
Problem Flowchart Program i.e
Program
(input) Coding

Program design Coding


4. Compilation
• After coding phase, next phase is to translate the
program into machine language.
• This translation can de done using C Compiler.
• C compiler takes source code as an input and
produce an object code i.e. machine code of the
program with the same name.
• The process of translating the program written in C
language(Source program) into machine
language(Object Program) is known as compilation.
High Level
Compiler Machine Language
Language

Source Code(Input) Object Code(Output)


• There may be some type of error in your
program and the compiler prints the message
for the particular errors.
• These error can be classified into different
categories-
– Compilation time error
– Run time error
– Logical error
– Syntax error
a) Compilation time error
• Compilation time error abort the compilation
process either immediately or following the
compilation phase in which they occur.
• No object code is produced.
• These error result from syntax error in the
source code
• E.g missing statement delimiters, mistyping
source filename etc.
b) Run Time error
• Run time errors may be caused due to a
number of factors like incorrect input, syntax
error, data type mismatch, incorrect control
flow etc.
• Normally run time errors are associated with
coding lacks.
c) Logical errors
• Logical errors are the errors which are caused
due to wrong program design and can not be
detected by compiler.
• They can be detected by watching the output
• E.g: if we want to multiply 2 numbers and
instead of multiplying we are going to divide
or subtract then there must be logical error
and we get the wrong output.
d) Syntax errors
• Syntax error occur when a program violates
the rules of grammar and expression of a
computer language.
• Syntax error are usually detected by system
software.
• Syntax error are very common error but they
are very easy to find out.
• E.g. by carelessness or keyboard errors.
5) Debugging and Testing
• A bug is an error in a computer program.
• The process of eliminating the errors in the program is
called as ‘Debugging’.
• If correct results are not obtained, the program
contains errors and if it contains error, it needs
debugging technique.
• Different errors can be eliminated by using various
methods.
• Normally hit and trial method is used to eliminate
errors.
• In this phase testing is also done to make sure that the
program is correct and performs its expected task for
all possible inputs.
6) Documentation
• In this phase each instruction of the program
and its purpose is written in easily
understandable form so that a lay man can
also understand the purpose of the program.
• This phase is also used to maintain and
upgrade the program in future.
7) Implementation and Maintenance
• In this phase program which is completely ready,
is installed at the site of the user.
• The user may have some errors and the
programmer has to maintain all these errors and
do all the necessary changes till the user gives the
green signal to the programmer.
• Even after its completion, maintenance of the
program at regular interval is compulsory so that
there must not be any problem in the output of
the program
Algorithm to calculate the factorial of a
number
step 1. Start
step 2. Read the number n
step 3. [Initialize]
i=1, fact=n
step 4. Repeat step 4 through 6 until i<n
step 5. fact=fact*i
step 6. i=i+1
step 7. Print fact
step 8. Stop
Flowchart to calculate the factorial of a number
Start

Read n

i=1
fact=n

Is i<n?

fact=fact*1
Print fact

i=i+1

Stop

You might also like