Example: Multiplying Two Numbers
1. Problem
Multiply two numbers and display the result.
2. Algorithm
Step-by-step solution in simple language:
-
Step 1: Store two inputs, a and b.
-
Step 2: Multiply a and b, store the result in c.
-
Step 3: Output c.
Note: Algorithm is written in natural language, easy to understand, independent of programming language.
3. Program
Implementation of the algorithm in C language:
Note: A program is written in a computer language, executed by a computer, and depends on hardware, operating system, and compiler.
Comparison: Algorithm vs Program
| Aspect |
Algorithm |
Program |
| Definition |
Step-by-step instructions to solve a problem |
Implementation of an algorithm using a programming language |
| Language |
Written in natural language |
Written in a computer language |
| Dependency |
Independent of OS and hardware |
Depends on OS, hardware, and compiler |
| Execution |
Conceptual – can be executed on paper |
Executed by a computer |
| Phase in SDLC |
Comes in Design/Planning Phase |
Comes in Implementation Phase |
| Steps |
Clear and unambiguous |
Detailed instructions extended for the computer |
| Testing |
No testing required on paper |
Needs compilation, debugging, and testing |