# Comparison of Programming Paradigms

Compare and Contrast Three Different Paradigms

# Problem:

**“Find the first n prime numbers, for n is any natural number.”**

Prime and Composite numbers are 2 categories under which the natural numbers greater than 1 are classified in mathematical world. Composite numbers are natural numbers greater than 1 and could be expressed as a product of 2 smaller natural numbers. All non-composite natural numbers greater than 1 are called Prime Numbers.

Now, let us investigate this problem in terms of various Programming Paradigms:

# Imperative Paradigm:

This is one of the oldest programming paradigms and is based on Von Neumann architecture. It executes step by step tasks by changing the state of the program. The objective of this type is on achieving the goal. C is an example for Imperative Paradigm. The given problem could be solved in C programming as:

# Object-Oriented Paradigm:

The Object-Oriented Programming Paradigm consists of programs written as a collection of Classes and Objects. Here the objects and functions are encapsulated inside a corresponding class. These objects and functionalities could be accessed using an instance of a class. It also depends on the access privileges in which the methods and objects are declared. Let us investigate how the problem of finding first n prime numbers could be solved in Object-Oriented programming with the help of Python Language:

# Logic Paradigm:

The Logic Paradigm is commonly termed as the abstract model of computation. It is very useful in solving puzzles and various logical questions. Here the program looks for the existing knowledge base about the problem or the knowledge acquired during the execution for solving the problems. This feature of Logic Paradigm is often related to the Artificial Intelligence and Machine Learning. Prolog is a good example of programming languages that work in this paradigm. Let us investigate how the given problem could be solved in Prolog:

# Comparison:

We were able to successfully generate a solution to find first n prime numbers in all three paradigms. Finally, let us compare and contrast what we observed in each paradigms while acquiring a solution.