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

Unit - 05 - Functions - 01

C functions are essential building blocks that encapsulate specific operations within a program, promoting code reusability and organization. Library functions in C, such as those found in the math.h header file, provide pre-defined operations to streamline coding. Additionally, conio.h offers functions for console manipulation, enhancing user interaction with the program.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Unit - 05 - Functions - 01

C functions are essential building blocks that encapsulate specific operations within a program, promoting code reusability and organization. Library functions in C, such as those found in the math.h header file, provide pre-defined operations to streamline coding. Additionally, conio.h offers functions for console manipulation, enhancing user interaction with the program.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Concept and need of function

WHAT IS C FUNCTION?

A large C program is divided into basic building blocks called C function. C function contains set
of instructions enclosed by “{ }” which performs specific operation in a C program. Actually,
Collection of these functions creates a C program.

#include<stdio.h>

/*Function prototypes*/

myfunc();

main()

myfunc();

/*Function Defination*/

myfunc()

printf("Hello, this is a test\n");

Need of functions in C

There are the following advantages of C functions.

 By using functions, we can avoid rewriting same logic/code again and again in a
program.
 We can call C functions any number of times in a program and from any place in a
program.
 We can track a large C program easily when it is divided into multiple functions.
 Reusability is the main achievement of C functions.
 However, Function calling is always a overhead in a C program.
Library Functions: Math functions

C –Library functions

Library functions in C language are inbuilt functions which are grouped together and placed in a
common place called library.

Each library function in C performs specific operation.

 We can make use of these library functions to get the pre-defined output instead of
writing our own code to get those outputs.
 These library functions are created by the persons who designed and created C
compilers.
 All C standard library functions are declared in many header files which are saved as
file_name.h.
 Actually, function declaration, definition for macros are given in all header files.
 We are including these header files in our C program using “#include<file_name.h>”
command to make use of the functions those are declared in the header files.
 When we include header files in our C program using “#include<filename.h>” command,
all C code of the header files are included in C program. Then, this C program is
compiled by compiler and executed.

C Math Functions

There are various methods in math.h header file. The commonly used functions of math.h
header file are given below.
C Math Functions Example

Let's see a simple example of math functions found in math.h header file

#include<stdio.h>

#include <math.h>

int main(){

printf("\n%f",ceil(3.6));

printf("\n%f",ceil(3.3));

printf("\n%f",floor(3.6));

printf("\n%f",floor(3.2));

printf("\n%f",sqrt(16));

printf("\n%f",sqrt(7));

printf("\n%f",pow(2,4));

printf("\n%f",pow(3,3));

printf("\n%d",abs(-12));

return 0;

Output:

4.000000

4.000000

3.000000

3.000000

4.000000

2.645751

16.000000

27.000000

12
Explain any four library functions under conio.h header file.

clrscr( ) -This function is used to clear the output screen.

getch( ) -It reads character from keyboard

getche( )-It reads character from keyboard and echoes to o/p screen

putch( ) - Writes a character directly to the console.

textcolor( )-This function is used to change the text color

textbackground( )-This function is used to change text background

You might also like