Starting with the code below, implement the power() function that calculates the equation: x raised to the power of y. You may assume that the inputs (x and y) and return value are 0 or positive integers (do not worry about handling negative numbers).
// Use this in your power() function
int my_power;
// Needed by the test
int answer;
void setup() {
Serial.begin(9600);
// Should be 9
answer = power(3, 2);
Serial.println(answer);
// Should be 5
answer = power(5, 1);
Serial.println(answer);
// Should be 1
answer = power(9, 0);
Serial.println(answer);
// Should be 16384
answer = power(2, 14);
Serial.println(answer);
// Should be 0
answer = power(0, 4);
Serial.println(answer);
}
void loop() {
// Do nothing
}
int power(int x, int y) {
// YOUR CODE GOES HERE
}
Hints:
When you run the program, you should see the following output:
