Tutte le sfide
Facile 0 risolte 0% di accettazione

Power by Repeated Multiplication

Raise a number to a power with a loop.

Compute base to the power exponent by multiplying base by itself exponent times in a loop. Any number to the power 0 is 1.

Implement power(base, exponent).

Input

base: The base. exponent: The exponent (zero or positive).

Output

Return base raised to exponent.

Vincoli

-10 ≤ base ≤ 10; 0 ≤ exponent ≤ 18

Esempi

Esempio 1
Input:
base = 2
exponent = 10

Output atteso:
expected = 1024
Input:
long long base = 2;
long long exponent = 10;

Output atteso:
long long expected = 1024;
Input:
long base = 2;
long exponent = 10;

Output atteso:
long expected = 1024;

Spiegazione

2 multiplied by itself 10 times is 1024.

Esempio 2
Input:
base = 5
exponent = 0

Output atteso:
expected = 1
Input:
long long base = 5;
long long exponent = 0;

Output atteso:
long long expected = 1;
Input:
long base = 5;
long exponent = 0;

Output atteso:
long expected = 1;

Spiegazione

Anything to the power 0 is 1.

Riferimenti

Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.

Impara dagli altri

Soluzioni della community

Nessuna soluzione pubblicata. Risolvi questa sfida per condividere la prima.