Library Function
Library functions are the built-in function in C++ programming. Programmer can use library function by invoking function directly; they don't need to write it themselves.Example 1: Library Function
# include <iostream>
#include <cmath>
using namespace std;
int main() {
double number, squareRoot;
cout<<"Enter a number: ";
cin>>number;
/* sqrt() is a library function to calculate square root */
squareRoot = sqrt(number);
cout<<"Square root of "<<number<<" = "<<squareRoot;
return 0;
}
OutputEnter a number: 26 Square root of 26 = 5.09902In example above,
sqrt()
library function is invoked to calculate the square root of a number. Notice code #include <cmath>
in the above program. Here, cmath
is a header file. The function definition of sqrt()
(body of that function) is written in that file. You can use all functions defined in cmath
when you include the content of file cmath
in this program using #include <cmath>
.Every valid C++ program has at least one function, that is,
main()
function
Show Konversi KodeHide Konversi Kode Show EmoticonHide Emoticon