- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the predefined functions in C language?
Functions are broadly classified into two types, which are as follows −
- Predefined functions
- User defined functions
Predefined (or) library functions
These functions are already defined in the system libraries.
Programmer will reuse the already present code in the system libraries to write error free code.
But to use the library functions, user must be aware of syntax of the function.
Example −
- sqrt() function is available in math.h library and its usage is −
y= sqrt (x) x number must be positive eg: y = sqrt (25) then ‘y’ = 5
- printf ( ) present in stdio.h library.
- clrscr ( ) present in conio.h library.
Example
Given below is the C program on predefined function sqrt, printf, conio −
#include<stdio.h> #include<conio.h> #include<math.h> main ( ){ int x,y; clrscr ( ); printf ("enter a positive number"); scanf (" %d", &x) y = sqrt(x); printf("squareroot = %d", y); getch(); }
Output
You will see the following output −
Enter a positive number 25 Squareroot = 5
Consider some more predefined functions −
- Cbrt(x) :cube root of x
- Log(x) : natural logarithm of x base e
- Ceils(x): round x to smaller integer not less than x
- Pow(x,y): x raised to power y………
Example
Following is a C program using the predefined functions −
#include<stdio.h> #include<math.h> main ( ){ int x,y,z,n,k,p,r,q; printf ("enter x and n values:"); scanf (" %d%d", &x,&y) y=cbrt(x); z=exp(x); k=log(x); p=ceil(x); q=pow(x,r); printf("cuberoot = %d", y); printf("exponent value = %d",z); printf("logarithmic value = %d", k); printf("ceil value = %d", p); printf("power = %d", q); getch(); }
Output
The output is stated below −
enter x and n values:9 2 cuberoot = 2 exponent value = 8103 logarithmic value = 2 ceil value = 9 power = 81
Advertisements