The pow() function defined in the math.h header file. It helps to return the value of the first argument(x) raised to the power of the second argument(y) i.e. xy.
double pow(double x, double y); #where x & y should be in double
The pow() function takes a single parameter in double. In this first argument is the base value and the second argument is the power value. Using the cast operator we can explicitly convert the type to double to find the power of type int, float, or long double.
Parameter | Description | Required / Optional |
---|---|---|
x | base value | Required |
y | power value | Required |
The return value of pow() function is a number in float.
Input | Return Value |
---|---|
x & y | xy is returned |
#include <stdio.h>
#include <math.h>
int main()
{
double B, P, output;
printf("Enter the base number: ");
scanf("%lf", &B);
printf("Enter the power raised: ");
scanf("%lf",&P);
output = pow(B,P);
printf("%.1lf^%.1lf = %.2lf", B, P, output);
return 0;
}
Output:
Enter the base number: 4.00 Enter the power raised: 2.00 4.00^2.00 = 16.00
#include <stdio.h>
#include <math.h>
int main () {
printf("Value 8.0 ^ 3 = %lf\n", pow(8.0, 3));
printf("Value 3.05 ^ 1.98 = %lf", pow(3.05, 1.98));
return(0);
}
Output:
Value 8.0 ^ 3 = 512.000000 Value 3.05 ^ 1.98 = 9.097324