समस्या
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
उदाहरण
इनपुट:
rate = 5.0
years = 2
principal = 1000.0
अपेक्षित आउटपुट:
expected = 1100.0
इनपुट:
double rate = 5.0;
long long years = 2;
double principal = 1000.0;
अपेक्षित आउटपुट:
double expected = 1100.0;
इनपुट:
double rate = 5.0;
long years = 2;
double principal = 1000.0;
अपेक्षित आउटपुट:
double expected = 1100.0;
व्याख्या
Each year earns 1000 × 5% = 50, so two years add 100: 1000 + 100 = 1100.
इनपुट:
rate = 0.0
years = 10
principal = 250.0
अपेक्षित आउटपुट:
expected = 250.0
इनपुट:
double rate = 0.0;
long long years = 10;
double principal = 250.0;
अपेक्षित आउटपुट:
double expected = 250.0;
इनपुट:
double rate = 0.0;
long years = 10;
double principal = 250.0;
अपेक्षित आउटपुट:
double expected = 250.0;
व्याख्या
With a 0% rate nothing is added, so the balance stays 250.
कैसे हल करें
पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।
संकेत 1
Simple interest हर साल original principal पर लगता है, बढ़ते balance पर नहीं.
संकेत 2
Yearly interest एक बार निकालो, फिर years से multiply करो.
संकेत 3
Final amount में starting principal के साथ accumulated interest भी शामिल होना चाहिए.
अपेक्षित जटिलता
समय O(1), अतिरिक्त स्थान O(1)
संदर्भ
यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।