Procedural Programming
What is Procedural Programming?
Procedural programming is a programming paradigm that uses a linear or top-down approach. It is based on the concept of procedure calls, where procedures (also known as routines, subroutines, or functions) are a set of instructions that perform a specific task.
Key Principles of Procedural Programming
Modularity: Code is divided into smaller, manageable sections called procedures or functions.
Sequence: Instructions are executed in a specific order, typically from top to bottom.
Iteration: Repeating a set of instructions using loops (e.g.,
for,while).Selection: Making decisions using conditional statements (e.g.,
if,switch).
Example of Procedural Programming
Here is a simple example in Python that demonstrates procedural programming by calculating the factorial of a number:
In this example:
The
factorialfunction is a procedure that calculates the factorial of a number.The
mainfunction handles user input and output.The program execution starts from the
mainfunction, demonstrating the top-down approach.