What are the programming paradigms- explain with e...
What are the programming paradigms- explain with e...
2. Procedural Programming:
○ Focus: Organizing code into procedures (functions) that encapsulate specific tasks.
○ Example:
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
4. Declarative Programming:
○ Focus: Specifying what the program should accomplish without explicitly stating
how to do it.
○ Example:
SELECT * FROM customers WHERE city = 'New York';
5. Functional Programming:
○ Focus: Treating computation as the evaluation of mathematical functions, avoiding
mutable state and side effects.
○ Example:
map (*2) [1, 2, 3] -- Returns [2, 4, 6]
6. Logic Programming:
○ Focus: Expressing problems as a set of logical rules and facts.
○ Example:
parent(alice, bob).
parent(bob, charlie).
grandparent(X, Y) :- parent(X, Z), parent(Z, Y).