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.
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 │
└─────────┘
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.
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
- Algorithm and Flowchart with Examples – C Programming Tutorial (video embedded above)
- GeeksforGeeks: How to Write an Algorithm
Next in this series: the structure of a C program, identifiers, and basic data types.