0% found this document useful (0 votes)
5 views

Computer

Uploaded by

ytgamingnp
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Computer

Uploaded by

ytgamingnp
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

UNIGLOBE SECONDARY SCHOOL

Kamaladi Ganesthan, Kathmandu

+2 MANAGEMENT

LAB REPORT 1: C PROGRAMMING

(COMPUTER SCIENCE)

SUBMITTED BY: SUBMITTED TO:

NAME: Manish Darai

GRADE: XII 'A2' Management

DATE :16th July 2023 (Mr. Navin Gurung)

KATHMANDU, NEPAL
2023

1
A Project On

C PROGAMMING

Submitted as a partial fulfillment of requirement of the curriculum of


GRADE-XII (Computer Science) under NEB

Submitted By:
Manish Darai

Under Supervision Of
Navin Gurung

Date:
16th July 2023

UNIGLOBE HIGER SECONDARY SCHOOL


Kamaladi Ganesthan, Kathmandu
Nepal

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.

The main objectives of the project are as follows;


1. To improve skill in C programming.
2. To improve knowledge in C programming
3. To familiar with C programming User defined functions.
4. To familiar with differnt types of user defined functions.

4
Table of Contents (TOC)

S.No. Page No.


1.Acknowledgement 3
2.Objectives 4
3.Table of Contents 5
4.Background Theory
4.1 C programming (6 - 9)
5.Work Done
5.1 Work Done in C programming (10 – 29)
6.Conclusion 30
7.Bibliography 31
8.Appendix 32

5
Questions for background theory
User defined function in C programming

Q1. What is a function? Write the features of a function in C programming.


A function in C programming is a self-contained block of code that performs a specific task. It is designed
to be reusable and modular, allowing you to break down complex programs into smaller, manageable
parts. Functions provide a way to organize code and make it easier to read, understand, and maintain.
Some features of functions in C programming include:
1. Modularity: Functions promote modular programming by dividing the code into smaller,
independent units.
2. Reusability: Functions can be called multiple times from different parts of the program, avoiding
code duplication.
3. Abstraction: Functions hide the implementation details and provide a higher-level interface to
perform a specific task.
4. Return value: Functions can return a value to the caller, allowing the result of the computation to
be used in other parts of the program.
5. Parameters: Functions can accept input parameters, enabling them to work with different data
values.
6. Function signature: Functions have a name, return type, and parameter list that define their
signature.

Q2. What is a user-defined function? Write the structure of a user-defined function.


A user-defined function in C programming is a function created by the programmer to perform a specific
task according to their requirements. The structure of a user-defined function typically consists of the
following parts:

Return_Type Function_Name(Parameter_List)
{
// Function Body
// Statements
// Return Statement (optional)
}

The parts of the user-defined function structure are explained below:

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.

Q3. What is a library function? Write the use of a library function in C


programming.
A library function in C programming refers to a function that is already implemented in a library and can
be used by including the appropriate header file. These functions are provided by the C standard library or
external libraries and offer a wide range of functionality. Library functions are pre-compiled and tested,
making them readily available for programmers to use in their programs.
The use of library functions in C programming includes:
Providing a set of ready-made functions to perform common tasks such as mathematical operations, string
manipulation, file handling, memory management, etc.
Reducing development time and effort by utilizing pre-existing, reliable code.
Promoting code reuse and modularity by abstracting complex operations into simple function calls.
Enhancing code readability and maintainability by leveraging well-documented and widely-used functions.

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.

A user-defined function in C programming consists of the following components:

 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.

Q7. Explain different types of User defined function with examples.


Different types of user defined function are as follows:
 Function with No Arguments and No Return Value:
Example: void greet() { printf("Hello!"); }
It performs a specific task without accepting any arguments or returning a value.
 Function with Arguments and No Return Value:
Example: void add(int a, int b) { int sum = a + b; printf("Sum: %d", sum); }
It performs a task using input arguments but does not return a value.
 Function with Arguments and a Return Value:
Example: int multiply(int a, int b) { return a * b; }
It accepts input arguments, performs a task, and returns a computed value.
 Function with No Arguments and a Return Value:
Example: int getRandomNumber() { return rand(); }
It performs a task without any arguments and returns a computed value.

9
Conclusion

C language is a powerful programming language to write programs. At the


end of this report we learned to write simple User definend functions using C
language. We understand the structure of a C function program, the
parameters and arguments with functions, main function and different
categories of User defined functions like returnable and non returnable
function. More programs in C language will be done in the next lab work.

10
Bibliography

Computer Text book


http://www.w3schools .com/

11
12

You might also like