Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

Library functions in C

Till now we have used user defined functions like the bedroom(), kitchen(), etc.
User defined functions are the functions defined/created by a programmer.
C also provides ready-made functions to us known as library functions. We have already used some of them.

Here are few examples of library (predefined) functions provided by C.

printf( ) – Output library function, used to print result on console.
scanf( ) – Input library function, used to feed input to the program.
malloc( ) – Used to provide dynamic memory allocation.
strlen( ) – Used to calculate the length of a string.
pow( ) – Used to find out the power of any number.

Example using library functions

#include<stdio.h>
#include<math.h>
int main()
{
    int num;
    long int ans;
    printf(" Enter any integer number = ");
    scanf("%ld",&num);
	
    ans = pow(num,2);  // call to library function pow()
    printf("\n Square of the entered number = %ld",ans);
	
    ans = pow(num,3);  // call to library function pow()
    printf("\n\n Cube of the entered number = %ld",ans);
	
    return 0;
}

Output

Enter any integer number = 5

Square of the entered number = 25

Cube of the entered number = 125

 
 

Leave a reply