Write function to ‘power’ which
-calculates square of a number when one argument is provided.
-calculates x raised to power y when two arguments are provided.
-calculates x raised to power y, raised to power z, when three arguments are provided.
#include <cmath>
double power(double n) {
return n*n;
}
double power(double n, double x) {
return pow(n, x);
}
double power(double n, double x, double y) {
return pow(n, pow(x, y));
}
Comments
Leave a comment