Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Library Functions in c

Uploaded by

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

Library Functions in c

Uploaded by

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

MS. R. S.

MORE
ME (COMPUTER)
Lecturer
Department of Information Technology

https://reenamorersm.wordpress.com/
Email: reena.more@rsmpoly.org
UNIT IV Library functions in c

FUNCTIONS Types of Functions


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.
LIST OF MOST USED HEADER FILES IN C
PROGRAMMING LANGUAGE:
MATH.H
“math.h” header file supports all the mathematical related functions in C
language. All the arithmetic functions used in C language are given below.
SQUARE ROOT USING SQRT() FUNCTION
#include <stdio.h>
#include <math.h>
int main()
{
float num, root;
printf("Enter a number: ");
scanf("%f", &num);
// Computes the square root of num and stores in root.
root = sqrt(num);
printf("Square root of %.2f = %.2f", num, root);
return 0;
}
CTYPE.H
C EXAMPLE PROGRAM OF ISALNUM()
#include<stdio.h>
#include<ctype.h>
int main()
{
char ch;
printf("Enter a character: ");
scanf("%c",&ch);
if(isalnum(ch))
printf("%c is an alphanumeric character.\n",ch);
else
printf("%c is not an alphanumeric character.\n",ch);
return 0;
}
C EXAMPLE PROGRAM OF ISPUNCT()
#include<stdio.h>
#include<ctype.h>
int main()
{
char ch;
printf("Enter a character: ");
scanf("%c",&ch);
if(ispunct(ch))
printf("%c is a punctuation character.\n",ch);
else
printf("%c is not a punctuation character.\n",ch);
return 0;
}
TIME.H
Time functions in c are used to interact with system time routine and
formatted time outputs are displayed.
TYPES OF FUNCTION
There are two types of function in C programming:
1. Standard library functions
2. User-defined functions
STANDARD LIBRARY FUNCTIONS
The standard library functions are built-in functions in C programming.
These functions are defined in header files.
The printf() is a standard library function to send formatted output to the
screen (display output on the screen). This function is defined in the stdio.h
header file.
Hence, to use the printf()function, we need to include the stdio.h header file
using #include <stdio.h>
USER-DEFINED FUNCTION
You can also create functions as per your need. Such functions created by the user are known as user-
defined functions.
#include <stdio.h>
void functionName()
{
... .. ...
}
int main()
{
... .. ...
functionName();
... .. ...
}
EXAMPLE: USER-DEFINED FUNCTION
#include <stdio.h>

int addNumbers(int a, int b); // function prototype

int main()

int n1,n2,sum;

printf("Enters two numbers: ");

scanf("%d %d",&n1,&n2);

sum = addNumbers(n1, n2); // function call

printf("sum = %d",sum);

return 0;

int addNumbers(int a, int b) // function definition

int result;

result = a+b;

return result; // return statement

You might also like