Unit I - Problemsolving - Intro
Unit I - Problemsolving - Intro
Problem Solving
Problem Solving
• Today, computers are all around us.
• We use them for doing various tasks like banking, railway
reservation, travel booking etc.
• All such task are complex without computers.
• Hence, Computers are used for solving various day-to-day
problems
• Thus problem solving is an essential skill that a computer science
student should know.
• It is pertinent to mention that computers themselves cannot solve a
problem.
• Precise step-by-step instructions should be given by us to solve
the problem.
• Thus, the success of a computer in solving a problem depends on
how correctly and precisely we define the problem and design a
solution .
• Problem solving is the process of identifying a problem,
developing an solution for the identified problem and finally
implementing the solution to develop a computer program.
STEPS FOR PROBLEM SOLVING
3 Coding - Pseudocode
• Example: Imagine an algorithm like a very well-written recipe for a dish, with
clearly defined steps that, if followed, one will end up preparing the dish.
• Before writing algorithm identify input, process and output.
• Input -> get from user
• Process -> task to be performed
• output -> final result.
Example Algorithm for addition of two numbers:
Step 1: Start
Step 2: Get two numbers say A , B
Step 3: Add the given numbers i.e Sum= A+B
Step 4: Display the result i.e print Sum
Step 5: Stop.
Example Algorithm for biggest among two numbers:
Step 1: Start
Step 2: Get two numbers say A , B
Step 3: Compare the given numbers i.e A>B or B>A
Step 4: Display the result i.e print biggest number
Step 5: Stop.
Try:
Area of Circle: Formula πr2
Perimeter of Circle: Formula 2πr
Example Algorithm for biggest among two numbers:
Step 1: Start
Step 2: Get two numbers say A , B
Step 3: Compare the given numbers i.e A>B or B>A
Step 4: Display the result i.e print biggest number
Step 5: Stop.
Try:
Area of Circle: Formula πr2
Perimeter of Circle: Formula 2πr
Flowchart
• A flowchart is a visual representation of an algorithm.
• Each shape represents a step of the solution process and the arrow
represents the order or link among the steps.
• It uses symbols and lines to show the inputs, outputs, and steps in a
process, as well as the connections between them.
• It is intended for human reading and cannot be executed directly by the computer.
• The word “pseudo” means “not real,” so “pseudocode” means “not real code”
• Example pseudocode:
INPUT
COMPUTE
INCREMENT
DECREMENT
IF/ELSE
WHILE
TRUE/FALSE
Advantages of pseudo code
END
Try
• To Calculate simple interest
• To check positive or negative number