Computer
Computer
+2 MANAGEMENT
(COMPUTER SCIENCE)
KATHMANDU, NEPAL
2023
1
A Project On
C PROGAMMING
Submitted By:
Manish Darai
Under Supervision Of
Navin Gurung
Date:
16th July 2023
2
ACKNOWLEDGEMENT
I would like to express my deep appreciation and gratitude to my subject teacher and
lecturer Mr. Navin Gurung (HOD), Mr. Binay Adhikari and and Mr. Rahul Ray for their
coinstantaneous help, advice, information and encouragement in this project.
I feel immense pleasure to present my project after a long work. Besides my effort, the help
and guideline given by many others hasn’t been unnoticed. I express my gratitude to all
those countless people for the support for me in doing this project.
I express my thanks to Uniglobe Secondary School / College for it has been a source of the
creation of this project and the support, valuable information, resources and guidance give
to me to do this project.
I am also grateful and indebt of my beloved friends for their immeasurable help, support
and encouragement from the beginning to the End of the project without whom this project
would not have been a reality.
Last but not the least I would like to thank my parents, family members, friends, this
College and other who help me for their guidance And support.
3
Objectives
Objective is a specific result that a person, a system aims to achieve within a time
frame and with available resources. In general, objectives are more specific and
easier to measure than goals. Objectives are basic tools that underline all planning
and strategic activities. They serve as a basic forecasting policy and evaluating
performance.
4
Table of Contents (TOC)
5
Questions for background theory
User defined function in C programming
Return_Type Function_Name(Parameter_List)
{
// Function Body
// Statements
// Return Statement (optional)
}
Return_Type: It specifies the data type of the value that the function returns to the caller. If the function
doesn't return a value, the return type is "void."
6
Function_Name: It is the name given to the function, which should be unique within the program.
Parameter_List: It contains the input parameters (if any) required by the function. Multiple parameters are
separated by commas.
Function Body: It contains the set of statements that define the actions performed by the function.
Return Statement (optional): If the function has a return type other than "void," it can include a return
statement to send a value back to the caller.
Q4. Write the difference between a library function and a user-defined function.
The main differences between a library function and a user-defined function in C programming are as
follows:
Origin: A library function is provided by a library, either the C standard library or an external
library, whereas a user-defined function is created by the programmer.
Availability: Library functions are already implemented and accessible by including the
appropriate header files, whereas user-defined functions need to be written by the programmer.
Customization: User-defined functions are tailored to the programmer's specific requirements and
can be designed to perform any task, whereas library functions offer pre-defined functionality that
may be more general-purpose.
Portability: Library functions are standardized and available across different platforms, ensuring
portability of code, whereas user-defined functions are specific to the program in which they are
defined.
Extensibility: User-defined functions can be easily modified or extended to accommodate
changing program needs, whereas library functions may require relying on updates or
enhancements provided by the library authors.
7
Q5. Write the function, syntax, and example of pow() and sqrt() functions.
The pow() function is used to calculate the power of a given base raised to an exponent. Its
syntax is as follows:
double pow(double base, double exponent);
Example usage:
#include <math.h>
#include <stdio.h>
int main() {
double result = pow(2.0, 3.0);
printf("2^3 = %.2f\n", result);
return 0;
}
Output:
2^3 = 8.00
The sqrt() function is used to calculate the square root of a given number. Its syntax is as follows:
double sqrt(double x);
Example usage:
#include <math.h>
#include <stdio.h>
int main() {
double result = sqrt(16.0);
printf("Square root of 16 = %.2f\n", result);
return 0;
}
Output:
Square root of 16 = 4.00
8
Q6. Explain the different components of a user-defined function.
Return Type: It specifies the data type of the value returned by the function to the caller. The
return type can be any valid C data type, including void if the function doesn't return a value.
Function Name: It is the identifier given to the function, which should be unique within the
program. The name should follow the naming conventions of C programming.
Parameter List: It contains the input parameters (if any) required by the function. Parameters
allow passing values into the function for processing. The list includes the data type and name of
each parameter, and multiple parameters are separated by commas.
Function Body: It is the block of statements enclosed within curly braces that define the actions
performed by the function. The function body contains the actual implementation of the task the
function is designed to accomplish.
Local Variables: These are variables declared within the function body and are accessible only
within the function's scope. Local variables are used to store temporary data during the execution
of the function.
Statements: These are the executable instructions written within the function body that perform
the desired operations. Statements can include assignments, control structures (if-else, loops),
function calls, and other C language constructs.
Return Statement: If the function has a return type other than void, a return statement can be used
to send a value back to the caller. The return statement terminates the function's execution and
returns control to the calling code.
9
Conclusion
10
Bibliography
11
12