Jak vypočítat jednoduchý a složený úrok

Jak vypočítat jednoduchý a složený úrok

Matematika je nedílnou součástí programování. Pokud nemůžete vyřešit jednoduché problémy v této oblasti, budete bojovat mnohem víc, než je třeba.





Naučit se, jak to udělat, naštěstí není příliš obtížné. V tomto článku se naučíte, jak vypočítat jednoduchý úrok a složený úrok pomocí Pythonu, C ++ a JavaScriptu.





jak získat wifi bez připojení k internetu

Jak vypočítáte jednoduchý úrok?

Jednoduchý úrok je metoda pro výpočet částky úroku účtovaného na principu částky za danou sazbu a za dané časové období. Jednoduchý úrok můžete vypočítat pomocí následujícího vzorce:





Simple Interest = (P x R x T)/100
Where,
P = Principle Amount
R = Rate
T = Time

Prohlášení o problému

Je ti dáno základní částka , úroková sazba , a čas . Musíte vypočítat a vytisknout jednoduchý úrok pro dané hodnoty. Příklad : Nechť princip = 1000, sazba = 7 a timePeriod = 2. Jednoduchý úrok = (princip * sazba * časové období) / 100 = (1000 * 7 * 2) / 100 = 140. Výstup je tedy 140.

Program C ++ pro výpočet jednoduchého úroku

Níže je program C ++ pro výpočet jednoduchého úroku:



// C++ program to calculate simple interest
// for given principle amount, time, and rate of interest.
#include
using namespace std;
// Function to calculate simple interest
float calculateSimpleInterest(float principle, float rate, float timePeriod)
{
return (principle * rate * timePeriod) / 100;
}

int main()
{
float principle1 = 1000;
float rate1 = 7;
float timePeriod1 = 2;
cout << 'Test case: 1' << endl;
cout << 'Principle amount: ' << principle1 << endl;
cout << 'Rate of interest: ' << rate1 << endl;
cout << 'Time period: ' << timePeriod1 << endl;
cout << 'Simple Interest: ' << calculateSimpleInterest(principle1, rate1, timePeriod1) << endl;
float principle2 = 5000;
float rate2 = 5;
float timePeriod2 = 1;
cout << 'Test case: 2' << endl;
cout << 'Principle amount: ' << principle2 << endl;
cout << 'Rate of interest: ' << rate2 << endl;
cout << 'Time period: ' << timePeriod2 << endl;
cout << 'Simple Interest: ' << calculateSimpleInterest(principle2, rate2, timePeriod2) << endl;
float principle3 = 5800;
float rate3 = 4;
float timePeriod3 = 6;
cout << 'Test case: 3' << endl;
cout << 'Principle amount: ' << principle3 << endl;
cout << 'Rate of interest: ' << rate3 << endl;
cout << 'Time period: ' << timePeriod3 << endl;
cout << 'Simple Interest: ' << calculateSimpleInterest(principle3, rate3, timePeriod3) << endl;
return 0;
}

Výstup:

Test case: 1
Principle amount: 1000
Rate of interest: 7
Time period: 2
Simple Interest: 140
Test case: 2
Principle amount: 5000
Rate of interest: 5
Time period: 1
Simple Interest: 250
Test case: 3
Principle amount: 5800
Rate of interest: 4
Time period: 6
Simple Interest: 1392

Související: Jak najít všechny faktory přirozeného čísla v C ++, Pythonu a JavaScriptu





Program Pythonu pro výpočet jednoduchého úroku

Níže je uveden program Python pro výpočet jednoduchého úroku:

# Python program to calculate simple interest
# for given principle amount, time, and rate of interest.
# Function to calculate simple interest
def calculateSimpleInterest(principle, rate, timePeriod):
return (principle * rate * timePeriod) / 100

principle1 = 1000
rate1 = 7
timePeriod1 = 2
print('Test case: 1')
print('Principle amount:', principle1)
print('Rate of interest:', rate1)
print('Time period:', timePeriod1)
print('Simple Interest:', calculateSimpleInterest(principle1, rate1, timePeriod1))
principle2 = 5000
rate2 = 5
timePeriod2 = 1
print('Test case: 2')
print('Principle amount:', principle2)
print('Rate of interest:', rate2)
print('Time period:', timePeriod2)
print('Simple Interest:', calculateSimpleInterest(principle2, rate2, timePeriod2))
principle3 = 5800
rate3 = 4
timePeriod3 = 6
print('Test case: 3')
print('Principle amount:', principle3)
print('Rate of interest:', rate3)
print('Time period:', timePeriod3)
print('Simple Interest:', calculateSimpleInterest(principle3, rate3, timePeriod3))

Výstup:





Test case: 1
Principle amount: 1000
Rate of interest: 7
Time period: 2
Simple Interest: 140.0
Test case: 2
Principle amount: 5000
Rate of interest: 5
Time period: 1
Simple Interest: 250.0
Test case: 3
Principle amount: 5800
Rate of interest: 4
Time period: 6
Simple Interest: 1392.0

Příbuzný: Jak dokončit výzvu FizzBuzz v různých programovacích jazycích

Program JavaScript pro výpočet jednoduchého úroku

Níže je uveden program JavaScript pro výpočet jednoduchého úroku:

// JavaScript program to calculate simple interest
// for given principle amount, time, and rate of interest.
// Function to calculate simple interest
function calculateSimpleInterest(principle, rate, timePeriod) {
return (principle * rate * timePeriod) / 100;
}
var principle1 = 1000;
var rate1 = 7;
var timePeriod1 = 2;
document.write('Test case: 1' + '
');
document.write('Principle amount: ' + principle1 + '
');
document.write('Rate of interest: ' + rate1 + '
');
document.write('Time period: ' + timePeriod1 + '
');
document.write('Simple Interest: ' + calculateSimpleInterest(principle1, rate1, timePeriod1) + '
');
var principle2 = 5000;
var rate2 = 5;
var timePeriod2 = 1;
document.write('Test case: 2' + '
');
document.write('Principle amount: ' + principle2 + '
');
document.write('Rate of interest: ' + rate2 + '
');
document.write('Time period: ' + timePeriod2 + '
');
document.write('Simple Interest: ' + calculateSimpleInterest(principle2, rate2, timePeriod2) + '
');
var principle3 = 5800;
var rate3 = 4;
var timePeriod3 = 6;
document.write('Test case: 3' + '
');
document.write('Principle amount: ' + principle3 + '
');
document.write('Rate of interest: ' + rate3 + '
');
document.write('Time period: ' + timePeriod3 + '
');
document.write('Simple Interest: ' + calculateSimpleInterest(principle3, rate3, timePeriod3) + '
');

Výstup:

Test case: 1
Principle amount: 1000
Rate of interest: 7
Time period: 2
Simple Interest: 140
Test case: 2
Principle amount: 5000
Rate of interest: 5
Time period: 1
Simple Interest: 250
Test case: 3
Principle amount: 5800
Rate of interest: 4
Time period: 6
Simple Interest: 1392

Jak vypočítat složený úrok

Složený úrok je přičtení úroku k částce jistiny. Jinými slovy, je to úrok z úroků. Složený úrok můžete vypočítat pomocí následujícího vzorce:

Amount= P(1 + R/100)T
Compound Interest = Amount – P
Where,
P = Principle Amount
R = Rate
T = Time

Prohlášení o problému

Je ti dáno základní částka , úroková sazba , a čas . Pro dané hodnoty musíte vypočítat a vytisknout složený úrok. Příklad : Nechť princip = 1000, sazba = 7 a doba Období = 2. Částka = P (1 + R/100) T = 1144,9 Složený úrok = Částka - Zásada Částka = 1144,9 - 1 000 = 144,9 Tedy výstup je 144,9.

Program C ++ pro výpočet složeného úroku

Níže je program C ++ pro výpočet složeného úroku:

// C++ program to calculate compound interest
// for given principle amount, time, and rate of interest.
#include
using namespace std;
// Function to calculate compound interest
float calculateCompoundInterest(float principle, float rate, float timePeriod)
{
double amount = principle * (pow((1 + rate / 100), timePeriod));
return amount - principle;
}
int main()
{
float principle1 = 1000;
float rate1 = 7;
float timePeriod1 = 2;
cout << 'Test case: 1' << endl;
cout << 'Principle amount: ' << principle1 << endl;
cout << 'Rate of interest: ' << rate1 << endl;
cout << 'Time period: ' << timePeriod1 << endl;
cout << 'Compound Interest: ' << calculateCompoundInterest(principle1, rate1, timePeriod1) << endl;
float principle2 = 5000;
float rate2 = 5;
float timePeriod2 = 1;
cout << 'Test case: 2' << endl;
cout << 'Principle amount: ' << principle2 << endl;
cout << 'Rate of interest: ' << rate2 << endl;
cout << 'Time period: ' << timePeriod2 << endl;
cout << 'Compound Interest: ' << calculateCompoundInterest(principle2, rate2, timePeriod2) << endl;
float principle3 = 5800;
float rate3 = 4;
float timePeriod3 = 6;
cout << 'Test case: 3' << endl;
cout << 'Principle amount: ' << principle3 << endl;
cout << 'Rate of interest: ' << rate3 << endl;
cout << 'Time period: ' << timePeriod3 << endl;
cout << 'Compound Interest: ' << calculateCompoundInterest(principle3, rate3, timePeriod3) << endl;
return 0;
}

Výstup:

Test case: 1
Principle amount: 1000
Rate of interest: 7
Time period: 2
Compound Interest: 144.9
Test case: 2
Principle amount: 5000
Rate of interest: 5
Time period: 1
Compound Interest: 250
Test case: 3
Principle amount: 5800
Rate of interest: 4
Time period: 6
Compound Interest: 1538.85

Příbuzný: Jak obrátit pole v C ++, Pythonu a JavaScriptu

zkratka spánku Windows 10 na ploše

Program Pythonu pro výpočet složeného úroku

Níže je uveden program Python pro výpočet složeného úroku:

# Python program to calculate compound interest
# for given principle amount, time, and rate of interest.
# Function to calculate compound interest
def calculateCompoundInterest(principle, rate, timePeriod):
amount = principle * (pow((1 + rate / 100), timePeriod))
return amount - principle
principle1 = 1000
rate1 = 7
timePeriod1 = 2
print('Test case: 1')
print('Principle amount:', principle1)
print('Rate of interest:', rate1)
print('Time period:', timePeriod1)
print('Compound Interest:', calculateCompoundInterest(principle1, rate1, timePeriod1))
principle2 = 5000
rate2 = 5
timePeriod2 = 1
print('Test case: 2')
print('Principle amount:', principle2)
print('Rate of interest:', rate2)
print('Time period:', timePeriod2)
print('Compound Interest:', calculateCompoundInterest(principle2, rate2, timePeriod2))
principle3 = 5800
rate3 = 4
timePeriod3 = 6
print('Test case: 3')
print('Principle amount:', principle3)
print('Rate of interest:', rate3)
print('Time period:', timePeriod3)
print('Compound Interest:', calculateCompoundInterest(principle3, rate3, timePeriod3))

Výstup:

Test case: 1
Principle amount: 1000
Rate of interest: 7
Time period: 2
Compound Interest: 144.9000000000001
Test case: 2
Principle amount: 5000
Rate of interest: 5
Time period: 1
Compound Interest: 250.0
Test case: 3
Principle amount: 5800
Rate of interest: 4
Time period: 6
Compound Interest: 1538.8503072768026

Příbuzný: Jak najít součet všech prvků v poli

Program JavaScript pro výpočet složeného úroku

Níže je uveden program JavaScript pro výpočet složeného úroku:

// JavaScript program to calculate compound interest
// for given principle amount, time, and rate of interest.

// Function to calculate compound interest
function calculateCompoundInterest(principle, rate, timePeriod) {
var amount = principle * (Math.pow((1 + rate / 100), timePeriod));
return amount - principle;
}
var principle1 = 1000;
var rate1 = 7;
var timePeriod1 = 2;
document.write('Test case: 1' + '
');
document.write('Principle amount: ' + principle1 + '
');
document.write('Rate of interest: ' + rate1 + '
');
document.write('Time period: ' + timePeriod1 + '
');
document.write('Compound Interest: ' + calculateCompoundInterest(principle1, rate1, timePeriod1) + '
');
var principle2 = 5000;
var rate2 = 5;
var timePeriod2 = 1;
document.write('Test case: 2' + '
');
document.write('Principle amount: ' + principle2 + '
');
document.write('Rate of interest: ' + rate2 + '
');
document.write('Time period: ' + timePeriod2 + '
');
document.write('Compound Interest: ' + calculateCompoundInterest(principle2, rate2, timePeriod2) + '
');
var principle3 = 5800;
var rate3 = 4;
var timePeriod3 = 6;
document.write('Test case: 3' + '
');
document.write('Principle amount: ' + principle3 + '
');
document.write('Rate of interest: ' + rate3 + '
');
document.write('Time period: ' + timePeriod3 + '
');
document.write('Compound Interest: ' + calculateCompoundInterest(principle3, rate3, timePeriod3) + '
');

Výstup:

Test case: 1
Principle amount: 1000
Rate of interest: 7
Time period: 2
Compound Interest: 144.9000000000001
Test case: 2
Principle amount: 5000
Rate of interest: 5
Time period: 1
Compound Interest: 250
Test case: 3
Principle amount: 5800
Rate of interest: 4
Time period: 6
Compound Interest: 1538.8503072768008

Naučte se kódovat zdarma: Začněte jednoduchým a složeným úrokem

V současné době se vliv kódování exponenciálně zvyšuje. A v souladu s tím exponenciálně roste i poptávka po zdatných kodérech. Mezi lidmi panuje mylná představa, že se mohou naučit kódovat až po zaplacení vysokého poplatku. Ale to není pravda. Můžete se naučit kódovat zcela zdarma z platforem jako freeCodeCamp, Khan Academy, YouTube atd. Takže i když nemáte velký rozpočet, nemusíte se obávat, že byste o něco přišli.

Podíl Podíl tweet E-mailem 7 nejlepších způsobů, jak se naučit kódovat zdarma

Zadarmo se nemůžete naučit kódovat. Pokud tyto vyzkoušené a vyzkoušené zdroje samozřejmě nevyužijete.

Číst dále
Související témata
  • Programování
  • Krajta
  • JavaScript
  • Návody na kódování
O autorovi Yuvraj Chandra(60 článků zveřejněno)

Yuvraj je studentem informatiky na univerzitě v Dillí v Indii. Je nadšený pro webový vývoj Full Stack. Když nepíše, zkoumá hloubku různých technologií.

Více od Yuvraj Chandra

Přihlaste se k odběru našeho zpravodaje

Připojte se k našemu zpravodaji a získejte technické tipy, recenze, bezplatné elektronické knihy a exkluzivní nabídky!

Kliknutím sem se přihlásíte k odběru