Compute the power of a base number.
#include <math.h> double pow(double x, double y); float powf(float x, float y); long double powl(long double x, long double y);
x
A floating point value to use as base.
y
A floating point value to use as exponent.
These functions compute xy .
These functions assign EDOM to errno if x is 0.0 and y is less than or equal to zero or if x is less than zero and y is not an integer. Use fpclassify() to check the validity of the results returned by these functions.
This facility may not be available on configurations of the EWL that run on platforms that do not have floating-point math capabilities.
#include <math.h> #include <stdio.h> int main(void) { double x; printf("Powers of 2:\n"); for (x = 1.0; x <= 10.0; x += 1.0) printf("2 to the %4.0f is %4.0f.\n", x, pow(2, x)); return 0; } Output: Powers of 2: 2 to the 1 is 2. 2 to the 2 is 4. 2 to the 3 is 8. 2 to the 4 is 16. 2 to the 5 is 32. 2 to the 6 is 64. 2 to the 7 is 128. 2 to the 8 is 256. 2 to the 9 is 512. 2 to the 10 is 1024.