簡単 6件解決済み 正答率100.0%

Simple Interest

Find the total amount after simple interest.

このチャレンジで学べること

  • Turn a word problem into a formula
  • Work with percentages
  • Return a decimal amount

問題

翻訳を表示

Money in a savings account earns simple interest: each year adds rate percent of the original amount principal. Compute the total balance after years years.

Implement simple_interest_total(principal, rate, years).

Input

principal: The starting amount. rate: The yearly interest rate in percent. years: The number of whole years.

Output

Return principal + principal × rate / 100 × years.

制約

0 ≤ principal ≤ 1,000,000; 0 ≤ rate ≤ 100; 0 ≤ years ≤ 100

例

例 1
入力:
principal = 1000.0
rate = 5.0
years = 2

期待される出力:
expected = 1100.0
入力:
double principal = 1000.0;
double rate = 5.0;
long long years = 2;

期待される出力:
double expected = 1100.0;
入力:
double principal = 1000.0;
double rate = 5.0;
long years = 2;

期待される出力:
double expected = 1100.0;

解説

Each year earns 1000 × 5% = 50, so two years add 100: 1000 + 100 = 1100.

例 2
入力:
principal = 250.0
rate = 0.0
years = 10

期待される出力:
expected = 250.0
入力:
double principal = 250.0;
double rate = 0.0;
long long years = 10;

期待される出力:
double expected = 250.0;
入力:
double principal = 250.0;
double rate = 0.0;
long years = 10;

期待される出力:
double expected = 250.0;

解説

With a 0% rate nothing is added, so the balance stays 250.

解き方のヒント

まずは自分で考えてから、ヒントを1つずつ開いてみましょう。

ヒント 1

Simple interest uses the original principal every year, not the growing balance.

ヒント 2

Compute the yearly interest once, then multiply by the number of years.

ヒント 3

Make sure the final amount includes the starting principal as well as the accumulated interest.

目安の計算量

O(1) time, O(1) extra space

参考資料

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

ランキング

全体ランキング

コーダーごとのいちばん良い合格解答です。速く、メモリが少なく、評価が高い解答ほど上位になります。

# コーダー 言語 時間 メモリ AI 評価 解答
1 УУмар Python 735 ms - 5/5 コードを見る
2 ДЗДавид Зайдулин Python 789 ms - 5/5 コードを見る
3 LMLaura Mahlow Python 842 ms - 5/5 コードを見る
4 HJhettory Jurash Python 844 ms - 4/5 コードを見る
5 GTGarlic The Destroyer Rust 1,265 ms - 5/5 コードを見る
6 PKPornchai Kaewkrabil Go 1,296 ms - 5/5 コードを見る

他の人の解答から学ぶ

コミュニティの解答

ネタバレ注意: この下に解答が6件あります まずは自分で挑戦してみましょう。他の開発者のコードやAIレビューも見ることができます。 サインインして課題を解くと議論に参加できます。