Tutte le sfide
Facile 4 risolte 100.0% di accettazione

Simple Interest

Find the total amount after simple interest.

Cosa imparerai

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

Problema

Mostra traduzione

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.

Vincoli

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

Esempi

Esempio 1
Input:
principal = 1000.0
rate = 5.0
years = 2

Output atteso:
expected = 1100.0
Input:
double principal = 1000.0;
double rate = 5.0;
long long years = 2;

Output atteso:
double expected = 1100.0;
Input:
double principal = 1000.0;
double rate = 5.0;
long years = 2;

Output atteso:
double expected = 1100.0;

Spiegazione

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

Esempio 2
Input:
principal = 250.0
rate = 0.0
years = 10

Output atteso:
expected = 250.0
Input:
double principal = 250.0;
double rate = 0.0;
long long years = 10;

Output atteso:
double expected = 250.0;
Input:
double principal = 250.0;
double rate = 0.0;
long years = 10;

Output atteso:
double expected = 250.0;

Spiegazione

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

Come affrontarlo

Prova prima da solo, poi apri un suggerimento alla volta.

Suggerimento 1

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

Suggerimento 2

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

Suggerimento 3

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

Complessità attesa

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

Riferimenti

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

La migliore soluzione superata di ogni programmatore. Le più veloci, leggere e meglio valutate stanno in alto.

# Programmatore Linguaggio Tempo Memoria Voto dell'IA Soluzione
1 УУмар Python 735 ms - 5/5 Vedi il codice
2 LMLaura Mahlow Python 842 ms - 5/5 Vedi il codice
3 HJhettory Jurash Python 844 ms - 4/5 Vedi il codice
4 GTGarlic The Destroyer Rust 1,265 ms - 5/5 Vedi il codice

Impara dagli altri

Soluzioni della community

Attenzione spoiler: 4 soluzioni complete sotto Prova prima a risolverla da solo. Puoi comunque sbirciare il codice degli altri sviluppatori e le recensioni AI. Accedi e risolvi la sfida per partecipare alla discussione.