すべてのチャレンジ
簡単 0件解決済み 正答率0%

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.

制約

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

例

例 1
入力:
base = 2
exponent = 10

期待される出力:
expected = 1024
入力:
long long base = 2;
long long exponent = 10;

期待される出力:
long long expected = 1024;
入力:
long base = 2;
long exponent = 10;

期待される出力:
long expected = 1024;

解説

2 multiplied by itself 10 times is 1024.

例 2
入力:
base = 5
exponent = 0

期待される出力:
expected = 1
入力:
long long base = 5;
long long exponent = 0;

期待される出力:
long long expected = 1;
入力:
long base = 5;
long exponent = 0;

期待される出力:
long expected = 1;

解説

Anything to the power 0 is 1.

参考資料

この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。

他の人の解答から学ぶ

コミュニティの解答

まだ公開された解答がありません。この課題を解いて最初の解答を共有しましょう。