0% found this document useful (0 votes)
11 views2 pages

Functions: Add - Numbers A B

Functions are code blocks that perform specific tasks and return values, while procedures perform actions without returning values. Functions take inputs and produce outputs, whereas procedures typically execute tasks like displaying messages. Both concepts enhance code organization and reusability in programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Functions: Add - Numbers A B

Functions are code blocks that perform specific tasks and return values, while procedures perform actions without returning values. Functions take inputs and produce outputs, whereas procedures typically execute tasks like displaying messages. Both concepts enhance code organization and reusability in programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Functions and procedures are essential concepts in programming, and they both help organize

code into reusable blocks. Here's a simple explanation:

Functions

●​ A function is a block of code that performs a specific task and returns a value.
●​ Functions take inputs (called parameters), process them, and produce an output.
●​ Example in Python:

def add_numbers(a, b):


return a + b # Returns the sum of a and b

Here, add_numbers is a function that takes two inputs (a and b) and returns their sum.

Procedures

●​ A procedure is similar to a function, but it doesn't return a value. Instead, it performs an


action.
●​ Example in Python:

def greet(name):
print(f"Hello, {name}!") # Displays a greeting

Here, greet is a procedure because it doesn’t return anything—it just prints a message.

Key Differences
Feature Function Procedure

Returns Yes No
value?

Purpose Solve problems, return Perform actions or


results tasks

Example Math calculation Printing a message


Both functions and procedures make programming more efficient by allowing you to reuse code
instead of rewriting it repeatedly. Would you like me to illustrate this further with another
example or in a different programming language? Let me know!

You might also like