Skip to content
“`html Programming Logic – Algorithm, Pseudocode & Flowchart

Programming Logic

Understanding Algorithms, Pseudocode and Flowcharts

1. What is Programming Logic?

Programming Logic is the process of deciding what instructions must be given to a computer and in what order those instructions should be executed.

Before writing a program in C, Java, Python or another programming language, it is useful to first think about the solution.

In simple words:

Programming Logic = What should the computer do + How should it do it?

Logic Building Tools

Tool Purpose
Algorithm Step-by-step solution written in simple human language.
Pseudocode Algorithm written using simple, programming-like notation.
Flowchart Graphical representation of the steps of a solution.
Problem
Algorithm
Pseudocode
Program

2. Algorithm

Definition: An algorithm is a step-by-step solution to a problem expressed in simple, human-understandable language.

Characteristics of a Good Algorithm

  • It should have a clear beginning and ending.
  • Steps should be arranged in the correct order.
  • Each step should be clear and unambiguous.
  • It should eventually produce the required result.
  • It should be easy to convert into a programming language.

Example: Store and Display a Number

Problem: Write an algorithm to store the number 25 and display it.

Algorithm – Detailed Version

  1. Start the program.
  2. Reserve some memory space to store a number.
  3. Store the value 25 in the allocated memory.
  4. Display the value stored in the memory.
  5. Stop the program.

Algorithm Using a Variable Name

  1. Start the program.
  2. Reserve memory to store a number and give the memory location the name a.
  3. Store the value 25 in a.
  4. Display the value stored in a.
  5. Stop the program.
Giving a meaningful name such as a to a memory location makes the algorithm easier to understand and later convert into code.

3. Pseudocode

Pseudocode is an alternative way of representing the steps of an algorithm using simple, standard, programming-like notation.

Pseudocode is sometimes called “false code” because it looks similar to programming code but does not follow the exact syntax of a particular programming language.

Algorithm vs Pseudocode

Algorithm Pseudocode
Written mainly in natural language. Uses programming-like statements.
Easy for beginners to understand. Closer to actual program structure.
Does not depend on programming syntax. Also generally language-independent.

Pseudocode for Storing and Displaying a Number

START

DECLARE a

a := 25

WRITE "Value of a = ", a

STOP
        
Note: Symbols such as := are commonly used in pseudocode to represent assignment. Pseudocode conventions can vary.

4. From Pseudocode to a Real Program

The same logic can be implemented in different programming languages. The algorithm remains essentially the same, but the syntax changes.

C Language

#include <stdio.h>

int main()
{
    int a;

    a = 25;

    printf("a = %d", a);

    return 0;
}
        

Java

public class Sample
{
    public static void main(String[] args)
    {
        int a;

        a = 25;

        System.out.println("a = " + a);
    }
}
        

Python

a = 25
print("a =", a)
        
Key Idea: The programming language changes, but the underlying logic can remain the same.

5. Example 1 – Sum of Two Numbers

Problem: Calculate and display the sum of any two numbers.

sum = a + b

Algorithm

  1. Start.
  2. Declare variables a, b and sum.
  3. Read the values of a and b.
  4. Calculate sum = a + b.
  5. Display sum.
  6. Stop.

Pseudocode

START

DECLARE a, b, sum

READ a
READ b

sum := a + b

WRITE "Sum = ", sum

STOP
        

6. Example 2 – Area of a Rectangle

Problem: Calculate and display the area of a rectangle for a given length and breadth.

Area = Length × Breadth

Algorithm

  1. Start.
  2. Declare length, breadth and area.
  3. Read the length.
  4. Read the breadth.
  5. Calculate area = length × breadth.
  6. Display the area.
  7. Stop.

Pseudocode

START

DECLARE length, breadth, area

READ length
READ breadth

area := length * breadth

WRITE "Area = ", area

STOP
        

7. Example 3 – Area of a Circle

Problem: Calculate and display the area of a circle for a given radius.

Area = π × radius²

For beginner-level calculations, we can use π = 3.14.

Algorithm

  1. Start.
  2. Declare radius and area.
  3. Read the radius.
  4. Calculate area = 3.14 × radius × radius.
  5. Display the area.
  6. Stop.

Pseudocode

START

DECLARE radius, area

READ radius

area := 3.14 * radius * radius

WRITE "Area of circle = ", area

STOP
        

8. Example 4 – Average of Three Numbers

Problem: Calculate and display the average of three numbers.

Average = (a + b + c) / 3

Algorithm

  1. Start.
  2. Declare a, b, c and avg.
  3. Read the three numbers.
  4. Calculate the average.
  5. Display the average.
  6. Stop.

Pseudocode

START

DECLARE a, b, c, avg

READ a
READ b
READ c

avg := (a + b + c) / 3

WRITE "Average = ", avg

STOP
        

9. Example 5 – Simple Interest

Problem: Calculate Simple Interest using principal, rate of interest and duration.

SI = (P × R × N) / 100

Where:

  • P = Principal amount
  • R = Rate of interest
  • N = Duration / Number of years
  • SI = Simple Interest

Algorithm

  1. Start.
  2. Declare p, r, n and si.
  3. Read the principal amount.
  4. Read the rate of interest.
  5. Read the duration.
  6. Calculate si = (p × r × n) / 100.
  7. Display the simple interest.
  8. Stop.

Pseudocode

START

DECLARE p, r, n, si

READ p
READ r
READ n

si := (p * r * n) / 100

WRITE "Simple Interest = ", si

STOP
        

10. Flowchart

A flowchart is a graphical representation of an algorithm. It uses standard symbols to represent different types of operations.

Common Flowchart Symbols

Symbol / Shape Name Purpose
Oval Terminator Represents Start or Stop.
Rectangle Process Represents a calculation or processing step.
Parallelogram Input / Output Represents reading input or displaying output.
Diamond Decision Represents a condition or decision.
Arrow Flow line Shows the direction of execution.

Simple Flow of a Program

START
INPUT
PROCESS
OUTPUT
STOP
A flowchart is especially useful when a program contains decisions, loops, or multiple paths.

11. How to Build Programming Logic

When you receive a programming problem, do not immediately start writing code. First break the problem into smaller steps.

Recommended Process

  1. Understand the problem
    Identify exactly what the problem is asking.
  2. Identify inputs
    Determine what information the user must provide.
  3. Identify processing
    Determine what calculations or decisions are required.
  4. Identify outputs
    Determine what the program must display.
  5. Write the algorithm
    Express the solution step by step.
  6. Write pseudocode
    Convert the algorithm into programming-like instructions.
  7. Write the actual program
    Convert the pseudocode into C, Java, Python, etc.
  8. Test the solution
    Try different input values and verify the output.
Remember the IPO model:

Input → Process → Output

12. Practice Questions

Level 1 – Basic Understanding

1. What is programming logic?
2. What is an algorithm?
3. What is pseudocode?
4. What is a flowchart?
5. What is the difference between an algorithm and pseudocode?
6. What are the three main tools used for logic building?

Level 2 – Write Algorithms

7. Write an algorithm to calculate the sum of two numbers.
8. Write an algorithm to calculate the product of two numbers.
9. Write an algorithm to calculate the area of a rectangle.
10. Write an algorithm to calculate the area of a circle.
11. Write an algorithm to calculate the average of five numbers.
12. Write an algorithm to calculate Simple Interest.
13. Write an algorithm to calculate the perimeter of a rectangle.
14. Write an algorithm to convert Celsius into Fahrenheit.
15. Write an algorithm to calculate the area of a triangle.
Area = (Base × Height) / 2

Level 3 – Write Pseudocode

16. Write pseudocode to calculate the sum of three numbers.
17. Write pseudocode to calculate the area and perimeter of a rectangle.
18. Write pseudocode to calculate the average of four numbers.
19. Write pseudocode to calculate Simple Interest and display it.
20. Write pseudocode to convert Fahrenheit to Celsius.

Level 4 – Logic Building

21. Write an algorithm to determine whether a number is positive or negative.
22. Write an algorithm to determine whether a number is even or odd.
23. Write an algorithm to find the larger of two numbers.
24. Write an algorithm to find the largest of three numbers.
25. Write an algorithm to determine whether a person is eligible to vote based on age.

Level 5 – Flowchart Practice

26. Draw a flowchart to calculate the sum of two numbers.
27. Draw a flowchart to calculate the area of a rectangle.
28. Draw a flowchart to determine whether a number is even or odd.
29. Draw a flowchart to find the larger of two numbers.
30. Draw a flowchart to calculate Simple Interest.

13. Challenge Problems

Challenge 1: A student has marks in three subjects. Write the algorithm and pseudocode to calculate total marks and percentage.
Challenge 2: Write an algorithm and pseudocode to calculate the final bill when the user enters quantity and price per item.
Challenge 3: Write an algorithm to convert a given number of days into years, weeks and remaining days.
Challenge 4: Write an algorithm and pseudocode to calculate the area and circumference of a circle.
Challenge 5: Write an algorithm, pseudocode and flowchart to determine whether a given number is divisible by both 3 and 5.

14. Quick Revision

Concept Remember
Programming Logic Deciding what instructions the computer should execute.
Algorithm Step-by-step solution in simple language.
Pseudocode Algorithm written in programming-like notation.
Flowchart Graphical representation of an algorithm.
Input Data supplied to the program.
Process Calculation or operation performed on the input.
Output Result produced by the program.
Golden Rule:
Understand the problem → Identify Input → Identify Process → Identify Output → Write Algorithm → Write Pseudocode → Draw Flowchart → Write Program → Test.
Programming Logic
Think First • Design the Logic • Then Write the Code
“`