16
Problem solving Problem solving using Computers using Computers By : David Livingston J Sudesh Kantila

Problem solving using Computer

Embed Size (px)

DESCRIPTION

A presentation on problem solving techniques

Citation preview

Page 1: Problem solving using Computer

Problem solving Problem solving using Computersusing Computers

By : David Livingston J

Sudesh Kantila

Page 2: Problem solving using Computer

Need for Programming Need for Programming LanguageLanguage1. We have some problem.2. We have to solve the problem.3. We can solve the problem, but we

don’t want to repeatedly solve the similar problems.

4. We want to use the computer to do this task for us whenever required.

5. We have to tell the computer, “How to solve the problem.”

Page 3: Problem solving using Computer

What is Problem?What is Problem?

A problem is an obstacle which makes it difficult to achieve a desired goal, objective or purpose.

It refers to a situation, condition, or issue that is yet unresolved.

In a broad sense, a problem exists when an individual becomes aware of a significant difference between what actually is and what is desired.

Page 4: Problem solving using Computer

What is Problem Solving?What is Problem Solving?

Every problem in the real world needs to be identified and solved. Trying to find a solution to a problem is known as problem solving.

Problem solving becomes a part of our day to day activity. Especially, when we use computers for performing our day to day activity.

Page 5: Problem solving using Computer

How to solve a problem?How to solve a problem?1. If you have a problem, either you

can solve it manually or using computer.

2. If the problem is easy enough, solve it manually or else use computers.

3. Bigger problems can be sub-divided into smaller problems (sub-problems) and start solving them one by one.

4. After completing solving sub-problems, the entire big problem has been solved easily.

Page 6: Problem solving using Computer

Algorithm – Logic to solveAlgorithm – Logic to solveIf you have solved any problem

already, you would have definitely used some procedure (logic) to do so.

There may be many different logic that can solve a single problem.

You may write this logic into small steps (easy enough) in english (or whatever language you understand).

This block of steps to solve the problem is called an “Algorithm”.

Page 7: Problem solving using Computer

A simple problem - A simple problem - FactorialFactorial

We have to calculate the factorial of a number ‘N’.

We know how to calculate the factorial.

Logic 1:N! = N * N-1 * N-2 * …* N-(N-1) {N-(N-1)=1}

Logic 2:N! = 1 * 2 * 3 * … * N

Logic 3:N! = N * (N-1)! (Recursion)

Page 8: Problem solving using Computer

Logic 1: (Algorithm)Logic 1: (Algorithm)1. START2. INPUT AN INTEGER – N3. LET F=14. IF N > 1 GOTO STEP 5 ELSE STEP 85. F = F * N6. N = N – 17. GOTO STEP 48. OUTPUT F9. STOP

Page 9: Problem solving using Computer

Logic 2: (Algorithm)Logic 2: (Algorithm)1. START2. INPUT AN INTEGER – N3. LET F=1, X=14. IF X < N GOTO STEP 5 ELSE STEP 85. X = X + 16. F = F * X7. GOTO STEP 48. OUTPUT F9. STOP

Page 10: Problem solving using Computer

Flow Chart – Graphical Flow Chart – Graphical AlgorithmAlgorithmAlgorithms are written in some

natural language, e.g. – English, हि�न्दी�, Chinease etc.

There may be some problem to understand the algorithm if a person from different region speaking a different language needs to know the logic.

To overcome this problem, logic may be represented in a graphical way.

This graphical representation of algorithm is called ‘Flow Chart’

Page 11: Problem solving using Computer

Flow Chart – Logic 1Flow Chart – Logic 1

LET F=1

IF N >

1

INPUT N

START

OUTPUT F

START

F = F * NN = N - 1

Yes

No

Page 12: Problem solving using Computer

Flow Chart – Logic 2Flow Chart – Logic 2

LET F=1 X = 1

IF X < N

INPUT N

START

OUTPUT F

START

X = X + 1F = F * X

No

Yes

Page 13: Problem solving using Computer

Common Flow Chart Common Flow Chart ShapesShapes

Flow LinesTerminator

Input / Output BoxProcess

Decision Box

(On Page and Off Page) ConnectorsPredefined Process

Page 14: Problem solving using Computer

PseudocodePseudocodePseudocode is a kind of structured

english for describing algorithms.It allows the designer to focus on the

logic of the algorithm without being distracted by details of language syntax. 

At the same time, the pseudocode needs to be complete. It describe the entire logic of the algorithm so that implementation becomes a rote mechanical task of translating line by line into source code (coding).

Pseudocode cannot be compiled nor executed, and there are no real formatting or syntax rules.

Page 15: Problem solving using Computer

Pseudocode – Logic 1Pseudocode – Logic 1GET value of NSET initial value of F to 1WHILE N > 1

F = F * NN = N – 1

ENDWHILEDISPLAY value of F

Page 16: Problem solving using Computer

Programming (Coding) in Programming (Coding) in CC

main(){int n;long f=1;printf(“Input n to get factorial: ”);scanf(“%i”,&n);while (n > 1){

f = f * n;n = n – 1;

}printf(“Factorial of %i is %li”,n,f);retrun 0;

}