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--;
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.