What is wrong with the following two functions? void Power ( int x, int y) { int
ID: 3609825 • Letter: W
Question
What is wrong with the following two functions?void Power ( int x, int y) { int result;
result = 1;
while ( y > 0 )
{ result = result * x;
y--;
}
}
and ...
void Power ( int& x, int& y, int&result) { result = 1;
while (y > 0)
{
result = result * x;
y--;
}
}
void Power ( int x, int y) { int result;
result = 1;
while ( y > 0 )
{ result = result * x;
y--;
}
}
and ...
void Power ( int& x, int& y, int&result) { result = 1;
while (y > 0)
{
result = result * x;
y--;
}
}
Explanation / Answer
void Power ( int x, int y) { int result;result = 1;
while ( y > 0 )
{ result = result * x;
y--;
}
} problems
1. It is only for Integers not double values.
2. The result is not returned from the function.
3. Can't Be used for negative power.
and ...
void Power ( int& x, int& y, int&result) { result = 1;
while (y > 0)
{
result = result * x;
y--;
}
}