What is pow() in C?
The pow() function in C is used to calculate the value of a base number raised to the power of the exponential declared.
The
pow()function is used in C by importing or including the<math.h>library. This library contains many other mathematical functions aside from thepow()function.
Syntax
double pow(double x, double y);
Parameters
x: a floating point number valuey: a floating point power value
Return value
pow() returns the value of x to the power of y.
Example
In the following example, we will look at the use of pow().
#include <stdio.h>// import the library#include <math.h>// the main functionint main() {// first exampledouble no1 = 5;double no1Exponent = 4.0;// second exampledouble no2 = 1.0;double no2Exponent = 0;// third exampledouble no3 = -20.00;double no3Exponent = -3;// generating results with the "pow()" methoddouble no1Result = pow(no1, no1Exponent);double no2Result = pow(no2, no2Exponent);double no3Result = pow(no3, no3Exponent);// Printing the resultsprintf("%lf to the power of %lf is : %lf\n", no1,no1Exponent, no1Result);printf("%lf to the power of %lf is : %lf\n", no2,no2Exponent, no2Result);printf("%lf to the power of %lf is : %lf\n", no3,no3Exponent, no3Result);return 0;}