Yahoo Clever wird am 4. Mai 2021 (Eastern Time, Zeitzone US-Ostküste) eingestellt. Ab dem 20. April 2021 (Eastern Time) ist die Website von Yahoo Clever nur noch im reinen Lesemodus verfügbar. Andere Yahoo Produkte oder Dienste oder Ihr Yahoo Account sind von diesen Änderungen nicht betroffen. Auf dieser Hilfeseite finden Sie weitere Informationen zur Einstellung von Yahoo Clever und dazu, wie Sie Ihre Daten herunterladen.

Stuck in solving a c++ problem?

Need to write a recursive function "power" that takes two arguments (base and exponent), and returns the power of the base number. For example, power(3, 4) = 3 * 3 * 3 * 3. Hint: The recursive step would use the following relationship: base to the power exponent = base x base to the power exponent – 1, and the terminating condition occurs when the argument exponent is equal to 1. Test your result for base = 5 and exponent = 3.

Your reply will be highly appreciated!

2 Antworten

Relevanz
  • Anonym
    vor 9 Jahren
    Beste Antwort

    This is not "being stuck", this is "don't want to do my homework, myself."

    Prove me wrong by posting what you did.

  • Jared
    Lv 6
    vor 9 Jahren

    agreed, show some work, this is a trivial function, especially for c++. If you don't know what recursive means, its means you call a function repeatedly inside itself until a certain condition is met. consider a pseudo code example as:

    function power(base,exponent)

    if (exponent > 1)

    ..value *= base*power(base,exponent-1)

    else

    ..return base

    return value

    end function power

    That little thing should help you along, but I am not writing the code for you as this is probably your homework, but many people don't understand the concept of recursion.

Haben Sie noch Fragen? Jetzt beantworten lassen.