#include <stdio.h>
int main() {
printf("\nNumber = %.2f", pow(2,3)); // Number = 4.00
printf("\nNumber = %.2f", pow(-2,3)); // Number = -8.00
printf("\nNumber = %.2f", pow(2,-3)); // Number = 0.12
printf("\nNumber = %.2f", pow(-2,-3)); // Number = -0.12
printf("\nNumber = %.2f", pow(0.2,4)); // Number = 0.00
return 0;
}
We will get first number to the power of second number ( x to the power of y ) by using pow()
function.
pow(x,y)
x, y = two input numbers .
Example with integer as inputs
#include <stdio.h>
#include <math.h>
int main(void){
int x,y,out;
x=2;
y=3;
out = pow(x,y);
printf("%d", out);
return 0;
}
The above code will give this output.
8
Example with float variables
pow(num1,num2);
Output is here
16.977535
Example with negative variables
#include <stdio.h>
#include <math.h>
int main(void){
float x,y,out;
x=2.3;
y=-3.4;
out = pow(x,y);
printf("%f", out);
return 0;
}
0.058901