The Wayback Machine - https://web.archive.org/web/20240910053448/https://www.geeksforgeeks.org/introduction-of-programming-paradigms/
Open In App

Introduction of Programming Paradigms

Last Updated : 21 Apr, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Paradigm can also be termed as method to solve some problem or do some task. Programming paradigm is an approach to solve problem using some programming language or also we can say it is a method to solve a problem using tools and techniques that are available to us following some approach. There are lots for programming language that are known but all of them need to follow some strategy when they are implemented and this methodology/strategy is paradigms. Apart from varieties of programming language there are lots of paradigms to fulfill each and every demand. They are discussed below:

1. Imperative programming paradigm: It is one of the oldest programming paradigm. It features close relation to machine architecture. It is based on Von Neumann architecture. It works by changing the program state through assignment statements. It performs step by step task by changing state. The main focus is on how to achieve the goal. The paradigm consist of several statements and after execution of all the result is stored.

Advantages: 

  1. Very simple to implement
  2. It contains loops, variables etc.

Disadvantage:  

  1. Complex problem cannot be solved
  2. Less efficient and less productive
  3. Parallel programming is not possible
Examples of Imperative programming paradigm:
C : developed by Dennis Ritchie and Ken Thompson
Fortran : developed by John Backus for IBM
Basic : developed by John G Kemeny and Thomas E Kurtz

C++
#include <iostream>

int main() {
    // Array to store marks
    int marks[5] = { 12, 32, 45, 13, 19 };

    // Variable to store the sum of marks
    int sum = 0;

    // Variable to store the average
    float average = 0.0;

    // Calculate the sum of marks
    for (int i = 0; i < 5; i++) {
        sum = sum + marks[i];
    }

    // Calculate the average
    average = sum / 5.0;

    // Output the average
    std::cout << "Average of five numbers: " << average << std::endl;

    return 0;
}
C
#include <stdio.h>

int main() {
    // Array to store marks
    int marks[5] = { 12, 32, 45, 13, 19 };

    // Variable to store the sum of marks
    int sum = 0;

    // Variable to store the average
    float average = 0.0;

    // Calculate the sum of marks
    for (int i = 0; i < 5; i++) {
        sum = sum + marks[i];
    }

    // Calculate the average
    average = (float)sum / 5.0;

    // Output the average
    printf("Average of five numbers: %.2f\n", average);

    return 0;
}
Java
public class Main {
    public static void main(String[] args) {
        // Array to store marks
        int[] marks = {12, 32, 45, 13, 19};

        // Variable to store the sum of marks
        int sum = 0;

        // Variable to store the average
        float average = 0.0f;

        // Calculate the sum of marks
        for (int i = 0; i < 5; i++) {
            sum = sum + marks[i];
        }

        // Calculate the average
        average = sum / 5.0f;

        // Output the average
        System.out.println("Average of five numbers: " + average);
    }
}
Python3
def main():
    # Array to store marks
    marks = [12, 32, 45, 13, 19]

    # Variable to store the sum of marks
    total_marks = sum(marks)

    # Calculate the average
    average = total_marks / len(marks)

    # Output the average
    print("Average of five numbers:", average)

if __name__ == "__main__":
    main()
#this code is added by Utkarsh
JavaScript
// Array to store marks
let marks = [12, 32, 45, 13, 19];

// Variable to store the sum of marks
let sum = 0;

// Variable to store the average
let average = 0.0;

// Calculate the sum of marks
for (let i = 0; i < 5; i++) {
    sum = sum + marks[i];
}

// Calculate the average
average = sum / 5.0;

// Output the average
console.log("Average of five numbers: " + average);

Output
Average of five numbers: 24.2

Imperative programming is divided into three broad categories: Procedural, OOP and parallel processing. These paradigms are as follows:

  • Procedural programming paradigm – 
    This paradigm emphasizes on procedure in terms of under lying machine model. There is no difference in between procedural and imperative approach. It has the ability to reuse the code and it was boon at that time when it was in use because of its reusability.
Examples of Procedural programming paradigm:
C : developed by Dennis Ritchie and Ken Thompson
C++ : developed by Bjarne Stroustrup
Java : developed by James Gosling at Sun Microsystems
ColdFusion : developed by J J Allaire
Pascal : developed by Niklaus Wirth

C++
#include <iostream>
using namespace std;
int main()
{
    int i, fact = 1, num;
    cout << "Enter any Number: ";
    cin >> number;
    for (i = 1; i <= num; i++) {
        fact = fact * i;
    }
    cout << "Factorial of " << num << " is: " << fact << endl;
    return 0;
}
Java
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // Create a Scanner object for reading input
        Scanner scanner = new Scanner(System.in);

        // Prompt user to enter a number
        System.out.println("Enter any Number: ");

        // Read number from user input
        int num = scanner.nextInt();

        // Initialize factorial to 1
        int fact = 1;

        // Calculate factorial using a for loop
        for (int i = 1; i <= num; i++) {
            fact = fact * i;
        }

        // Print the factorial of the number
        System.out.println("Factorial of " + num + " is: " + fact);
    }
}
Python3
# Prompt user to enter a number
num = int(input("Enter any Number: "))

fact = 1  # Initialize factorial variable

# Calculate factorial
for i in range(1, num + 1):
    fact = fact * i

# Print the factorial
print("Factorial of", num, "is:", fact)
JavaScript
// Prompt the user for input
let num = prompt("Enter any Number: ");

// Initialize the factorial value to 1
let fact = 1;

// Calculate the factorial of the number
for (let i = 1; i <= num; i++) {
    fact = fact * i;
}

// Print the factorial of the number
console.log("Factorial of " + num + " is: " + fact);

Then comes OOP,

  • Object oriented programming – 
    The program is written as a collection of classes and object which are meant for communication. The smallest and basic entity is object and all kind of computation is performed on the objects only. More emphasis is on data rather procedure. It can handle almost all kind of real life problems which are today in scenario.

Advantages: 

  • Data security
  • Inheritance
  • Code reusability
  • Flexible and abstraction is also present
Examples of Object Oriented programming paradigm:
Simula : first OOP language
Java : developed by James Gosling at Sun Microsystems
C++ : developed by Bjarne Stroustrup
Objective-C : designed by Brad Cox
Visual Basic .NET : developed by Microsoft
Python : developed by Guido van Rossum
Ruby : developed by Yukihiro Matsumoto
Smalltalk : developed by Alan Kay, Dan Ingalls, Adele Goldberg

C++
// C++ program for the above approach
#include <bits/stdc++.h>
using namespace std;

// Class Signup
class Signup {
    int userid;
    string name;
    string emailid;
    char sex;
    long mob;

public:
    // Function to create and object using
    // the parameters
    void create(int userid, string name, string emailid,
                char sex, long mob)
    {
        cout << "Welcome to GeeksforGeeks\nLets create "
                "your account\n";
        this->userid = 132;
        this->name = "Radha";
        this->emailid = "radha.89@gmail.com";
        this->sex = 'F';
        this->mob = 900558981;
        cout << "your account has been created" << endl;
    }
};

// Driver Cpde
int main()
{
    cout << "GfG!" << endl;

    // Creating Objects
    Signup s1;
    s1.create(22, "riya", "riya2@gmail.com", 'F', 89002);

    return 0;
}
Java
import java.io.*;

class GFG {
    public static void main(String[] args)
    {
        System.out.println("GfG!");
        Signup s1 = new Signup();
        s1.create(22, "riya", "riya2@gmail.com", 'F',
                  89002);
    }
}

class Signup {
    int userid;
    String name;
    String emailid;
    char sex;
    long mob;

    public void create(int userid, String name,
                       String emailid, char sex, long mob)
    {
        System.out.println(
            "Welcome to GeeksforGeeks\nLets create your account\n");
        this.userid = 132;
        this.name = "Radha";
        this.emailid = "radha.89@gmail.com";
        this.sex = 'F';
        this.mob = 900558981;
        System.out.println("your account has been created");
    }
}
Python3
class Signup:
    def __init__(self):
        self.userid = 0
        self.name = ""
        self.emailid = ""
        self.sex = ""
        self.mob = 0

    def create(self, userid, name, emailid, sex, mob):
        print("Welcome to GeeksforGeeks\nLets create your account\n")
        self.userid = 132
        self.name = "Radha"
        self.emailid = "radha.89@gmail.com"
        self.sex = 'F'
        self.mob = 900558981
        print("your account has been created")


if __name__ == "__main__":
    print("GfG!")
    s1 = Signup()
    s1.create(22, "riya", "riya2@gmail.com", 'F', 89002)
C#
using System;

class GFG {
    static void Main(string[] args)
    {
        Console.WriteLine("GfG!");
        Signup s1 = new Signup();
        s1.create(22, "riya", "riya2@gmail.com", 'F',
                  89002);
    }
}

class Signup {
    public int userid;
    public string name;
    public string emailid;
    public char sex;
    public long mob;

    public void create(int userid, string name,
                       string emailid, char sex, long mob)
    {
        Console.WriteLine(
            "Welcome to GeeksforGeeks\nLets create your account\n");
        this.userid = 132;
        this.name = "Radha";
        this.emailid = "radha.89@gmail.com";
        this.sex = 'F';
        this.mob = 900558981;
        Console.WriteLine("your account has been created");
    }
}
// This code is contributed by akshatve2zi2
JavaScript
class Signup {
    constructor(userid, name, emailid, sex, mob) {
        this.userid = userid;
        this.name = name;
        this.emailid = emailid;
        this.sex = sex;
        this.mob = mob;
    }
    
    create(userid, name, emailid, sex, mob) {
        console.log("Welcome to GeeksforGeeks\nLets create your account\n");
        this.userid = 132;
        this.name = "Radha";
        this.emailid = "radha.89@gmail.com";
        this.sex = 'F';
        this.mob = 900558981;
        console.log("your account has been created");
    }
}

console.log("GfG!");
let s1 = new Signup();
s1.create(22, "riya", "riya2@gmail.com", 'F', 89002);
// This code is contributed by akshatve2zi2

Output
GfG!
Welcome to GeeksforGeeks
Lets create your account

your account has been created

  • Parallel processing approach – 
    Parallel processing is the processing of program instructions by dividing them among multiple processors. A parallel processing system posses many numbers of processor with the objective of running a program in less time by dividing them. This approach seems to be like divide and conquer. Examples are NESL (one of the oldest one) and C/C++ also supports because of some library function.

2. Declarative programming paradigm: 
It is divided as Logic, Functional, Database. In computer science the declarative programming is a style of building programs that expresses logic of computation without talking about its control flow. It often considers programs as theories of some logic.It may simplify writing parallel programs. The focus is on what needs to be done rather how it should be done basically emphasize on what code is actually doing. It just declares the result we want rather how it has be produced. This is the only difference between imperative (how to do) and declarative (what to do) programming paradigms. Getting into deeper we would see logic, functional and database.

  • Logic programming paradigms – 
    It can be termed as abstract model of computation. It would solve logical problems like puzzles, series etc. In logic programming we have a knowledge base which we know before and along with the question and knowledge base which is given to machine, it produces result. In normal programming languages, such concept of knowledge base is not available but while using the concept of artificial intelligence, machine learning we have some models like Perception model which is using the same mechanism. 
    In logical programming the main emphasize is on knowledge base and the problem. The execution of the program is very much like proof of mathematical statement, e.g., Prolog
predicates
sumoftwonumber(integer, integer).
clauses
sumoftwonumber(0, 0).
sumoftwonumber(N, R) :-
N > 0,
N1 is N - 1,
sumoftwonumber(N1, R1),
R is R1 + N.

  • Functional programming paradigms – 
    The functional programming paradigms has its roots in mathematics and it is language independent. The key principle of this paradigms is the execution of series of mathematical functions. The central model for the abstraction is the function which are meant for some specific computation and not the data structure. Data are loosely coupled to functions.The function hide their implementation. Function can be replaced with their values without changing the meaning of the program. Some of the languages like perl, javascript mostly uses this paradigm.
Examples of Functional programming paradigm:
JavaScript : developed by Brendan Eich
Haskell : developed by Lennart Augustsson, Dave Barton
Scala : developed by Martin Odersky
Erlang : developed by Joe Armstrong, Robert Virding
Lisp : developed by John Mccarthy
ML : developed by Robin Milner
Clojure : developed by Rich Hickey

The next kind of approach is of Database.

  • Database/Data driven programming approach – 
    This programming methodology is based on data and its movement. Program statements are defined by data rather than hard-coding a series of steps. A database program is the heart of a business information system and provides file creation, data entry, update, query and reporting functions. There are several programming languages that are developed mostly for database application. For example SQL. It is applied to streams of structured data, for filtering, transforming, aggregating (such as computing statistics), or calling other programs. So it has its own wide application.
CREATE DATABASE databaseAddress;
CREATE TABLE Addr (
PersonID int,
LastName varchar(200),
FirstName varchar(200),
Address varchar(200),
City varchar(200),
State varchar(200)
);



Similar Reads

Difference between Functional Programming and Object Oriented Programming
What is Functional Programming?In functional programming, we have to build programs using functions. An example of functional programming is Haskell language. What is Object Oriented Programming?Object-oriented programming is built by using classes and objects. In this, we have concepts of encapsulation, inheritance, polymorphism, and Data abstract
3 min read
Which Programming Language to Choose?
One of the most annoying question today is which programming language should be chosen for the sake of education/career or anything. Answer for this question to many programmers ends up with C or C++, or mostly Java but why C? why C++? Why Java?. Today many software exists, to solve a problem but also to interfere with another software. nowadays in
4 min read
Differences between Procedural and Object Oriented Programming
This article focuses on discussing the differences between procedural and object-oriented programming. Procedural Programming Procedural Programming can be defined as a programming model which is derived from structured programming, based upon the concept of calling procedure. Procedures, also known as routines, subroutines or functions, simply con
2 min read
Hello World Program : First program while learning Programming
In this article, I'll show you how to create your first Hello World computer program in various languages. Along with the program, comments are provided to help you better understand the terms and keywords used in theLearning program. Programming can be simplified as follows: Write the program in a text editor and save it with the correct extension
6 min read
Design Goals and Principles of Object Oriented Programming
The fundamental goal of dealing with the complexity of building modern software naturally gives rise to several sub-goals. These sub-goals are directed at the production of quality software, including good implementations of data structures and algorithms. The article focuses on discussing design goals and principles of Object Oriented Programming.
13 min read
What are Objects in Programming?
In object-oriented programming (OOP), objects are the basic entities that actually exists in the memory. Each object is based on a blueprint of attributes and behaviours (variables and functions) defined as Class. The basic purpose of a Class is to identify the common attributes and behaviours and group them as an entity that can be reused again an
2 min read
Best Practices of Object Oriented Programming (OOP)
As the name suggests, Object-Oriented Programming or OOPs refers to languages that use objects in programming. Object-oriented programming aims to implement real-world entities like inheritance , abstraction , polymorphism, and encapsulation in programming. The main aim of OOP is to bind together the data and the functions that operate on them so t
5 min read
If-Then-___ Trio in Programming
Learning to code is a bit like discovering magic spells, and one trio of spells you'll encounter often is called "If-Then-___." These spells help your code make decisions like a wizard choosing the right spell for a particular situation. Table of Content If-Then-ElseIf-Then-TernaryIf-Then-ThrowIf-Then-Async/AwaitWhen to use each If-Then-___ Trio in
2 min read
Complete Reference for Bitwise Operators in Programming/Coding
There exists no programming language that doesn't use Bit Manipulations. Bit manipulation is all about these bitwise operations. They improve the efficiency of programs by being primitive, fast actions. There are different bitwise operations used in bit manipulation. These Bitwise Operators operate on the individual bits of the bit patterns. Bit op
13 min read
What is a Code in Programming?
In programming, "code" refers to a set of instructions or commands written in a programming language that a computer can understand and execute. In this article, we will learn about the basics of Code, types of Codes and difference between Code, Program, Script, etc. Table of Content What is Code?Code in Programming Language:Types of CodeDifferent
10 min read
Most Famous Online IDE for Programming
Integrated Development Environment (IDE) provides crucial tools for software development. IDE provides developers with tools like code editor, compiler, interpreter, debugger, code library, and testing tools that help developers in writing, compiling, debugging, and testing the code. Without IDE developers have to do every task individually. IDE in
5 min read
Basic Programming Problems
Learn Programming – How To Code In the world of programming, mastering the fundamentals is key to becoming a proficient developer. In this article, we will explore a variety of basic programming problems that are essential for every aspiring coder to understand. By delving into these foundational challenges, you will gain valuable insights into pro
4 min read
Basics of Computer Programming For Beginners
Be it any programming language in which you want to grow your career, It's very important to learn the fundamentals first. Before having a good command over the basic concepts of programming, you cannot imagine the growth in that particular career. Hence, this article will talk about all the basic concepts of programming. Also, if you're a beginner
7 min read
Programming vs Coding - A Short Comparison Between Both
The terms "programming" and "coding" are often used interchangeably, but they can have slightly different nuances in meaning. Programming is a broader and more encompassing term that involves various activities throughout the software development lifecycle, while coding is a specific task within programming that deals with writing the actual lines
3 min read
Top 10 Programming Tips For Beginners
Whether you are a novice or have just started to learn programming, there are key tips that can significantly enhance your learning experience. In this blog post, we'll explore the top 10 programming tips for beginners that can help you build a strong foundation and navigate the complexities of coding with confidence. Top 10 Programming Tips For Be
8 min read
7 Ways To Make Programming More Interesting For Beginners
How to make programming more interesting, exciting, and fun...?? It is indeed the common query of almost every programmer, especially the beginner ones. Let's find an effective solution to it in this article.   It’s the 21st day of June and the year is 1948. It is a pleasant summer day for many but for mathematician and computer engineer Tom Kilbur
7 min read
A Freshers Guide To Programming
Since the boom of the IT sector, computer science has become the key to the door of future evergrowing careers. Everyone knows it (You're seriously living under a rock if you aren't aware of this yet). With software so rooted in the functionality of society, Programming is one of the most desirable skills in the present scenario. Being able to inve
3 min read
What are the 4 types of programming?
The term "types of programming" can refer to different aspects or classifications within the field of programming. One common way to categorize programming is based on the programming paradigm or style. There are four main programming paradigms: Imperative Programming: In imperative programming, the focus is on describing how a program operates by
2 min read
What are Operators in Programming?
Operators in programming are essential symbols that perform operations on variables and values, enabling tasks like arithmetic calculations, logical comparisons, and bitwise manipulations. In this article, we will learn about the basics of operators and their types. Table of Content What are Operators in Programming?Types of Operators in Programmin
15+ min read
Getting Started with Menu Driven Programs in Programming
Have you ever used a menu to choose options on a computer or a phone? Menu-driven programs in programming work similarly. They offer users a menu of choices to select from, making it easy to interact with the program. In this article, we will start from the basics of creating menu-driven programs, suitable for beginners and experienced programmers
3 min read
Getting Started with Words and Sentences Programs in Programming
Welcome to the world of words and sentences programming! In this article, we will explore the basics of words and sentences programs in programming. We will start by introducing the concept of words and sentences in programming, and then we will discuss some simple programs that you can write to manipulate words and sentences. By the end of this ar
2 min read
Getting Started with Number Programs in Programming
Numbers play a crucial role in programming, whether it's dealing with simple digits or diving into more complex concepts like number systems, arithmetic, series, sequences, random numbers, and special numerical values. This article is your guide to understanding how to code numbers in programming, unlocking a world of computational opportunities. L
2 min read
Getting Started with Geometry Problems in Programming
Geometry is a key aspect of programming, helping us create shapes, graphics, and solve spatial problems. From points and lines to circles, triangles, rectangles, squares, and polygons, learning how to code for geometry can unlock a world of creative possibilities in software development. This article will guide you through the basics of coding for
2 min read
Getting Started with Date and Time Problems in Programming
In the world of programming, handling dates and times is essential for many applications. From converting dates to working with time zones, years, weeks, and days, understanding how to code for date and time opens up a world of possibilities. This article will guide you through date and time conversions, year, week, and day programs, helping you be
2 min read
Getting Started with Printing Patterns in Programming
Printing patterns in programming is a fun and creative way to enhance your coding skills. Whether you are a beginner or an experienced programmer, mastering pattern printing can help you understand logic, loops, and problem-solving techniques in a visual manner. In this article, we will explore the basics of printing patterns in programming, starti
1 min read
Control flow statements in Programming
Control flow refers to the order in which statements within a program execute. While programs typically follow a sequential flow from top to bottom, there are scenarios where we need more flexibility. This article provides a clear understanding about everything you need to know about Control Flow Statements. Table of Content What are Control Flow S
15+ min read
If statement in Programming
An if statement is a fundamental control structure in programming languages that allows you to execute specific code blocks based on whether a condition is true or false. It is used to make decisions and control the flow of execution in your program. Table of Content What is an If Statement?Example of If Statement in ProgrammingConditional Operator
9 min read
Bitwise AND operator in Programming
In programming, Bitwise Operators play a crucial role in manipulating individual bits of data. One of the fundamental bitwise operators is the Bitwise AND operator (&amp;). In this article, we'll dive deep into what is Bitwise AND operator, its syntax, properties, applications, and optimization techniques, and conclude with its significance in prog
6 min read
Finally Block in Programming
The finally block in programming, commonly used in languages like Java and C#, is a block of code that is executed regardless of whether an exception is thrown or not. It is typically used in conjunction with a try-catch block to ensure certain cleanup or finalization tasks are performed, such as closing resources like files or database connections
6 min read
Goto Statement in Programming
Goto statement is a control flow statement present in certain programming languages like C and C++. It enables programmers to transfer program control to a labeled section of code within the same function or block. Despite its availability, its usage is often discouraged in modern programming practices due to its potential to complicate code struct
3 min read