Problem Solving Techniques Using C
Problem Solving Techniques Using C
in
Problem solving
• It is a systematic approach to find and
implement the solution to a problem.
Program
• It is a set of instructions written in computer
languages
Software
• It is a collection of computer data and
instructions. It is responsible for controlling,
integration and managing hardware
components and perform specific tasks.
Classification of software
• System software
It is a set of one or more programs that manage
and support a computer system hardware and its
data processing activities.
E-x Operating system, Compilers, Assemblers
• Application software
It is a set of one or more programs, designed to
solve a specific problem or a specific task.
E-x Ms-word ,Ms-excel,Ms-powerpoint
Problem Definition
• To solve a problem, the first step is to identify
and define the problem.
• The problem must be stated clearly, accurately
and precisely.
Problem Analysis
• The problem analysis helps in designing and
coding for that particular problem.
1. Input specifications
The number of inputs and what forms the input
are available
2.Output specifications
The number of outputs and what forms the
output should be displayed.
E-x input – a,b,c
output - c
Designing a program
• 1. Algorithms
• 2.Flowcharts
• Algorithm - step by step procedure of solving
a problem
• Flowcharts – It is the graphical representation
of the algorithm.
Coding
• Writing instructions in a particular language to
solve a problem.
Testing a Program
• After writing a program, programmer needs to
test the program for completeness,
correctness, reliability and maintainability.
• Unit testing
• Program Testing
• Verification Testing
• Validation Testing
Algorithm
• An algorithm is a step by step procedure to solve
a given problem in finite number of steps.
The characteristics of an algorithm are
(i) Algorithm must have finite number of steps.
(ii) No instructions should be repeated.
(iii) An algorithm should be simple.
(iii) An algorithm must take atleast one or more
input values.
(iv) An algorithm must provide atleast one or more
output values.
Advantages
• An algorithms are very easy to understand.
• Algorithm is programming language
independent.
• Algorithm makes the problem simple, clear,
correct.
Example-1
Problem definition : To find simple interest
Problem Analysis :
inputs – p, r, t
Output – simple interest
Algorithm
Step 1:Start
Step 2:input p,r,t
Step 3: calculate si=p*r*t/100
Step 4: output si
Step 5:stop File Downloaded From www.Bustudymate.in
File Downloaded From www.Bustudymate.in
Example - 2
Problem definition : To Convert temperature in Celsius to
Fahrenheit
Problem Analysis :
input – c
Output – f
Algorithm
Step 1:Start
Step 2:input c
Step 3: calculate f=9/5*c+32
Step 4: output f
Step 5:stop
File Downloaded From www.Bustudymate.in
File Downloaded From www.Bustudymate.in
Example - 3
• Problem definition : To find the largest of three numbers
• Problem Analysis :
input - a,b,c
output – string
Algorithm
step 1: start
step 2: input a,b,c
Step 3: if a> a d a> the pri t a is greater
Else if >a a d > the pri t is greater
Else
Pri t is greater
Step 4: stop
FLOWCHART
• A flow chart is a step by step diagrammatic
representation of the logic paths to solve a
given problem.
• A flowchart is graphical representation of an
algorithm.
Advantages
• The flowchart shows the logic of a problem
displayed in pictorial fashion
• It is useful for debugging and testing of
programs.
• Program could be coded efficiently using
flowcharts.
• The Flowchart is good means of
communication to other users.
File Downloaded From www.Bustudymate.in
File Downloaded From www.Bustudymate.in
Disadvantages
• It is not useful to represent complex program
logic
• For any alterations, the flowcharts have to be
redrawn completely.
Input/output
• Used to read or print data or information
Processing
• Represents calculations, Processing or data
manipulation.
Decision
• Represents comparisons or decisions and
branching
Looping
• Represents a group of instructions to be
executed repeatedly.
Connectors
• Indicates an entry or an exit to another part of
the flowchart.
Directions of flow
• Indicates the direction of processing or flow of
control.
Coding
• Coding is the translation of an algorithm or
flowchart into a suitable computer language
c,c++,java
Debugging
• It is the process of identifying and correcting
the bugs.
Documentation
• Documentation is the reference material which
explains the use and maintenance of the
program.
• Two types of documentation
Internal Documentation
variable names, program code
External Documentation
User’s a ual, Ad i istrator a uals,
Developers manual
Maintenance
• Periodic review of the program and
modifications based on their user
requirements.
Structured Programming
• Structured programming is a technique for
organizing and coding computer programs in
which a hierarchy of modules is used ,each
having single entry and single exit point.
Three types of control structures
Sequence
Selection
Iteration
File Downloaded From www.Bustudymate.in
File Downloaded From www.Bustudymate.in
Modular programming
• The modular approach to programming
involves breaking a program down into sub-
components called modules.
• Each module is composed of some set of
instructions.