Algorithms and Flowcharts: Solving Problems Before You Code

Before you write a single line of C code, you need a plan. That plan comes in two forms: an algorithm (a step-by-step set of instructions written in plain language) and a flowchart (the same steps drawn as a diagram using standard symbols). This is Post 1 of the Unit I series on the fundamentals of C.

Why bother with a plan first: Jumping straight into code without a plan is how bugs, infinite loops, and half-finished logic happen. An algorithm forces you to think through every step and every edge case (what if the input is zero? negative? empty?) before syntax even enters the picture.

What Is an Algorithm?

An algorithm is a finite sequence of well-defined steps that takes an input and produces an output, solving a specific problem. A good algorithm is:

  • Unambiguous — each step has exactly one clear meaning.
  • Finite — it must terminate after a limited number of steps.
  • Effective — each step must be simple enough to actually carry out.

Example: Algorithm to Find the Largest of Three Numbers

Step 1: Start
Step 2: Read three numbers a, b, and c
Step 3: If a > b and a > c, then largest = a
Step 4: Else if b > c, then largest = b
Step 5: Else largest = c
Step 6: Print largest
Step 7: Stop

What Is a Flowchart?

A flowchart is the visual counterpart of an algorithm. It uses standard shapes so that anyone (not just programmers) can follow the logic at a glance:

  • Oval — Start / Stop (terminal points)
  • Parallelogram — Input / Output
  • Rectangle — Process (a calculation or assignment)
  • Diamond — Decision (a yes/no question, branching the flow)
  • Arrows — Flow of control from one step to the next

Flowchart for the Same “Largest of Three Numbers” Problem

        ┌─────────┐
        │  Start  │
        └────┬────┘
             │
        ┌────▼─────────────┐
        │ Read a, b, c      │
        └────┬──────────────┘
             │
        ┌────▼─────────┐   Yes   ┌───────────────┐
        │  a > b AND    ├────────▶│ largest = a   │
        │  a > c ?      │         └───────┬───────┘
        └────┬──────────┘                 │
           No│                            │
        ┌────▼─────────┐   Yes            │
        │   b > c ?     ├─────────────────┤
        └────┬──────────┘                 │
           No│                            │
        ┌────▼─────────┐                  │
        │ largest = c   │                  │
        └────┬──────────┘                  │
             │◀────────────────────────────┘
        ┌────▼──────────────┐
        │ Print largest      │
        └────┬───────────────┘
             │
        ┌────▼────┐
        │  Stop   │
        └─────────┘
Drawing tip: You don’t need special software to practice — pen and paper (or a simple diagram tool) is enough while you’re learning. What matters is getting comfortable with the shapes and the discipline of tracing every possible path, including the “no” branches of every decision.

From Algorithm to C Code

Once the logic is nailed down on paper, translating it into C becomes mechanical:

#include <stdio.h>

int main() {
    int a, b, c, largest;

    printf("Enter three numbers: ");
    scanf("%d %d %d", &a, &b, &c);

    if (a > b && a > c) {
        largest = a;
    } else if (b > c) {
        largest = b;
    } else {
        largest = c;
    }

    printf("Largest number is: %d\n", largest);

    return 0;
}

Sample Output

Enter three numbers: 12 45 7
Largest number is: 45

Notice how directly each line of code corresponds to a step in the algorithm and a shape in the flowchart. This is the entire point of planning first: by the time you sit down to write C syntax, all the actual thinking is already done.

Common student mistake: Skipping this planning step for “simple” problems is fine once you’re experienced, but for anything with multiple conditions or loops, writing the algorithm first (even just 3-4 lines of pseudocode) will save far more time than it costs — most logic bugs are caught at this stage, not while debugging code.

Summary

  • An algorithm is a step-by-step plain-language solution to a problem.
  • A flowchart is the same logic drawn using standard symbols (oval, parallelogram, rectangle, diamond).
  • Both force you to fully think through a problem — including edge cases and decision branches — before writing any code.
  • Well-planned logic translates almost line-for-line into C.

Further Reading

Next in this series: the structure of a C program, identifiers, and basic data types.

Leave a Comment