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

Problem Solving Techniques Using C

Uploaded by

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

Problem Solving Techniques Using C

Uploaded by

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

File Downloaded From www.Bustudymate.

in

SUBJECT: PROBLEM SOLVING TECHNIQUES


USING C
SEMESTER: I SEMESTER
COURSE: BCA
SUBJECT TEACHER: Dr. K.Chitra,
Assistant Professor,
Department of Computer Science

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

PROBLEM SOLVING TECHNIQUES


USING C
Chapter – 1
Introduction to computer
programming

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Problem solving
• It is a systematic approach to find and
implement the solution to a problem.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Program
• It is a set of instructions written in computer
languages

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Software
• It is a collection of computer data and
instructions. It is responsible for controlling,
integration and managing hardware
components and perform specific tasks.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

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

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Steps in Problem Solving


• Problem Definition
• Problem Analysis
• Design
• Coding
• Testing
• Maintenance

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

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.

E-x Find largest of three numbers

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

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

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

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.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Coding
• Writing instructions in a particular language to
solve a problem.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

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

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Maintaining the program


• It means periodic review of the programs and
modifications based on user requirements.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

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.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Advantages
• An algorithms are very easy to understand.
• Algorithm is programming language
independent.
• Algorithm makes the problem simple, clear,
correct.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

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

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

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.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

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.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Rules for writing flowcharts


• It should be drawn from top to bottom.
• A flowchart always begins with start symbol
and ends with stop symbol.
• Flow lines are used to join the symbols
• Decision box should have one entry point and
two exit points.
• For lengthy flowcharts, connectors are used to
join them.
File Downloaded From www.Bustudymate.in
File Downloaded From www.Bustudymate.in

Symbols used in flowcharts

start or stop (terminal)


• Oval: Rectangle with rounded sides is used to
indicate either START/ STOP of the program.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Input/output
• Used to read or print data or information

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Processing
• Represents calculations, Processing or data
manipulation.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Decision
• Represents comparisons or decisions and
branching

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Looping
• Represents a group of instructions to be
executed repeatedly.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Connectors
• Indicates an entry or an exit to another part of
the flowchart.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Directions of flow
• Indicates the direction of processing or flow of
control.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in
Write Algorithm and flowchart for the
following problems
• Find the largest of two numbers
• Check whether the given number is positive or
not
• Input a age of person and check whether he is
eligible for voting or not.
• Check whether the given number is odd or
even
• Check whether the given year is leap year or
not.
File Downloaded From www.Bustudymate.in
File Downloaded From www.Bustudymate.in

Coding
• Coding is the translation of an algorithm or
flowchart into a suitable computer language
c,c++,java

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Testing and Debugging


• To achieve the required output, the program
that is written in coding must be tested
,compiled and executed.
• Types of errors
syntax error
semantic error
Run-time error

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Debugging
• It is the process of identifying and correcting
the bugs.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

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

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Maintenance
• Periodic review of the program and
modifications based on their user
requirements.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

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

Rules for structured programming


• Every program should specify input and
output variables.
• The flow of the program should be top-down
approach.
• Every program and function must have a
comment at the beginning.
• Divide the big programs in to subprograms
(functions or procedures).
• Documentation should be short.
File Downloaded From www.Bustudymate.in
File Downloaded From www.Bustudymate.in
Advantages of structured
programming
• Easy to write.
• Easy to debug
• Easy to understand
• Easy to change.

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.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Advantages of modular programming


• Easy to write
• Easy to debug
• The types of approaches
Top-down approach
Bottom-up approach

File Downloaded From www.Bustudymate.in

You might also like