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 the pow() function.

Syntax

double pow(double x, double y);

Parameters

  • x: a floating point number value
  • y: 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 function
int main() {
// first example
double no1 = 5;
double no1Exponent = 4.0;
// second example
double no2 = 1.0;
double no2Exponent = 0;
// third example
double no3 = -20.00;
double no3Exponent = -3;
// generating results with the "pow()" method
double no1Result = pow(no1, no1Exponent);
double no2Result = pow(no2, no2Exponent);
double no3Result = pow(no3, no3Exponent);
// Printing the results
printf("%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;
}

Free Resources