Ask Question

Write the definition of a method powerto, which receives two parameters. the first is a double and the second is an int. the method returns a double. if the second parameter is negative, the method returns zero. otherwise it returns the value of the first parameter raised to the power of the second parameter.

+1
Answers (1)
  1. 25 May, 12:19
    0
    The case of x⁰=1 is one you shouldn't overlook!

    double powerto (double f, int exponent)

    {

    if (exponent < 0) { return 0; }

    if (exponent = = 0) { return 1.0; }

    while (--exponent > 0) { f * = f; }

    return f;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write the definition of a method powerto, which receives two parameters. the first is a double and the second is an int. the method returns ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers