pow() Function In C Programming

Power is a mathematical function that is used to calculate the power of the specified number. C programming language provides the pow()function which is an implementation of the mathematical power. In this tutorial, we examine how to use the pow() function in order to calculate mathematical power.

pow() Function Syntax

The pow() function has the following syntax. The pow() function returns a double value too. The pow() function is provided via the math.h library which should be also included in order to use pow() function.

double pow(double BASE,double VALUE)
  • BASE is the base number which is a double.
  • VALUE is the power number which is a double.

Calculate Power

In the following example, we calculate 3^3 and 3.33^2 . The pow() function requires two-parameter which are double. As the pow() function returns double it can be printed with the %lf .

#include <stdio.h>
#include <math.h>

int main () {

   printf("3.0 ^ 3 = %lf\n", pow(3.0, 3));

   printf("3.33 ^ 2 = %lf", pow(3.33, 2));
   
   return(0);
}

Calculate Negative Power

The pow() function can be used to calculate negative power.

#include <stdio.h>
#include <math.h>

int main () {

   printf("3.0 ^ -2 = %lf\n", pow(3.0, -2));

   printf("3.33 ^ -3 = %lf", pow(3.33, -3));
   
   return(0);
}

Leave a Comment