pow in c

What is pow in c programming?

The function pow in c is used to calculate power of a number w.r.t. given base value.

This function is defined in math.h header file.

Prototype

#include<math.h>
double pow(double value1,double value2);

Parameters of pow in c

pow function takes two double type values as input parameters.

Return value of pow in c

This function returns power raised of a given number w.r.t. given base value.


Example program for pow in c

Example1

#include<stdio.h>
#include<math.h>
int main()
{
  double val1=20,val;
  double val2=2;
  val=pow(val1,val2);
  printf("\n\n\tThe result is %lf \n\n",val);
  return 0;
}
Example 1 for pow in c programming
Example 1 for pow in c programming

While using gcc use below command to add math header.

gcc file_name.c -lm

Code explanantion

The power value of a given number is found by calling the pow function and the result is stored in a variable. This result is printed on to the console.


Example2

#include<stdio.h>
#include<math.h>
int main()
{
  double x,y,res;
  printf("\n\n\tEnter the values of x,y \n\t");
  scanf("%lf %lf",&x,&y);
  res=pow(x,y);
  printf("\n\tThe result is %lf \n\n",res);
  return 0;
}
Example 2 for pow in c programming
Example 2 for pow in c programming

While using gcc use below command to add math header.

gcc file_name.c -lm

Code explanation

The power of a number that is inputted from the user is found by calling the pow function. The result is printed on to the console.

pow() Man page


Difference between pow and sqrt in c

pow is used to calculate the power of a number raised to the base value. sqrt function is used to calculate the square root of a given number.

pow function takes two arguments. sqrt function takes one argument.

Prototypes are as follows

double pow(double value1,double value2);

double sqrt(double value1);
pow in csqrt in c
Used to calculate power of a number raised to the base value.Used to calculate square root of a given number.
double pow(double value1,double value2);double sqrt(double value1);

Difference between pow and exp in c

pow is used to calculate the power of a number raised to the base value. exp function is used to calculate the exponential value of a given number.

pow function takes two parameters. exp function takes one parameter.

Prototypes are as follows

double pow(double value1,double value2);

double exp(double value1);
pow( )exp( )
Used to calculate power of a number raised to the base value.Used to calculate exponential value of a given number.
double pow(double value1,double value2);double exp(double value1);
Takes two parameters.Takes one parameter.

People also ask for

What is pow in c?

The function pow in c is used to calculate the power of a number w.r.t. given base value. This function is defined in math.h header file.