POW Function in C Programming

The POW function in C programming calculates the Power of a specified value or number. For example, if x is the base value and 2 is the exponent, then pow(x, 2) = x² and the syntax of this function is

double pow(double base, double Exponent);
  • Please specify the base value and Exponent Exponent value or power here.

POW Function in C Programming Example

The POW function is used to return the Power of the given number. In this program, we will find the power of both positive and negative values and display the output using this method and the printf statement.

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

int main()
{
  int result1; 
  double result2, result3, result4, result5;
   
  result1 = pow(5, 3);
  printf("\n The Final result of %d Power %d = %d ", 5, 3, result1);
  
  result2 = pow(2, 0);
  printf("\n The Final result of %d Power %d = %f ", 2, 0, result2);
  
  result3 = pow(0, 2);
  printf("\n The Final result of %d Power %d = %f ", 0, 2, result3);
  
  result4 = pow(-2, 3);
  printf("\n The Final result of %d Power %d = %f ", -2, 3, result4);
  
  result5 = pow(3, -4);
  printf("\n The Final result of %d Power %d = %f ", 3, -4, result5);
  
  return 0;
}
POW in C programming 1

Example 2

This program asks the user to enter his/her own base and exponent values. And then, it will calculate the power of user-specified values.

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

int main()
{
  int result, base, exponent;
  
  printf("\n Please Enter the Base and Exponent Values : \n ");
  scanf("%d %d", &base, &exponent);
  
  result = pow(base, exponent);
  
  printf("\n The Final result of %d Power %d = %d ", base, exponent, result);
  
  return 0;
}
 Please Enter the Base and Exponent Values :  
 2
 5

 The Final result of 2 Power 5 = 32