Index 2 (Udf Other 3 Types)
Index 2 (Udf Other 3 Types)
OBJECTIVES
Area Calculation of a Rectangle using different types of User-defined Functions
I. To demonstrate the use of user-defined functions in C programming.
II. To calculate and display the area of a rectangle using different types of user-defined
functions.
III. To understand the concepts of return values and arguments in user-defined functions.
REQUIREMENTS
1. C Compiler (e.g., GCC) 2. Computer System
3. IDE or Text Editor 4. OS compatible with the software
THEORY
In C programming, user-defined functions allow us to create our own functions apart from the
built-in functions provided by the language. These functions can be customized to perform
specific tasks. In this project, we will focus on calculating and displaying the area of a rectangle
using three different types of user-defined functions.
1. Yes Return and No Argument: This type of function returns a value but does not require any
arguments. The function declaration would look like: `int aor(void);`.
2. No Return and Yes Argument: This type of function does not return a value but requires one
or more arguments. The function declaration would look like: `void aor(int, int);`.
3. Yes Return and Yes Argument: This type of function both returns a value and requires one or
more arguments. The function declaration would look like: `int aor(int, int);`.
Here “aor” stands for “Area of Rectangle”.
// Function prototype
int aor(void);
int main()
1
INDEX 1B
{
int result;
// Call the aor() function and store the returned value in 'result'
result = aor();
return 0;
}
Output:
// Function declaration
2
INDEX 1B
int main()
{
int length, width;
return 0;
}
3
INDEX 1B
int main()
{
int length, width, result;
return 0;
}
return area;
}
Output:
CONCLUSION
In this project, we successfully implemented three types of user-defined functions to calculate
and display the area of a rectangle. We observed that each type of function has its own syntax
and usage. The program demonstrated the concepts of return values and arguments in user-
defined functions. By using user-defined functions, we can modularize our code and perform
specific tasks efficiently.