Problem Solving using Computer (Lesson)

Problem Solving using Computer

Programming is not just about writing syntax; it's about solving problems logically. Before touching the keyboard, we must define the strategy.

2.1 The Problem-Solving Life Cycle

  1. Requirement Analysis: Understand what the problem is.
  2. Algorithm Design: Plan the step-by-step solution.
  3. Flowcharting: Visualize the logic.
  4. Coding: Translate the logic into a programming language.
  5. Testing & Debugging: Find and fix errors.

2.2 Algorithms

An algorithm is a finite set of step-by-step instructions to solve a specific problem.

Characteristics of a Good Algorithm:

  • Input: It should have zero or more inputs.
  • Output: It must produce at least one output.
  • Definiteness: Each step must be clear and unambiguous.
  • Finiteness: It must stop after a finite number of steps.
  • Effectiveness: Steps must be basic enough to be performed.

Example Algorithm: Add two numbers

  1. START
  2. Declare variables A, B, and SUM.
  3. Read values for A and B.
  4. Add A and B and store the result in SUM (SUM = A + B).
  5. Display SUM.
  6. STOP

2.3 Flowcharts

A flowchart is a graphical representation of an algorithm.

Standard Flowchart Symbols:

SymbolNameDescription
TerminalTerminalStart or End of the program.
Input/OutputInput/OutputUsed for reading or writing data.
ProcessProcessArithmetic operations and data manipulation.
DecisionDecisionUsed for conditions (True/False).

2.4 Pseudocode

Pseudocode (False Code) is an informal way of writing an algorithm using plain English mixed with programming logic markers like IF, THEN, ELSE, WHILE.

Example Pseudocode: Check if a number is Even or Odd

BEGIN
    READ number
    IF number % 2 == 0 THEN
        PRINT "Number is Even"
    ELSE
        PRINT "Number is Odd"
    ENDIF
END

Refer to the Lecture Slides for visual examples of complex flowcharts.

PREVIOUS
Introduction to C Programming
NEXT
Getting Started