So berechnen Sie einfache und Zinseszinsen
Mathematik ist ein integraler Bestandteil der Programmierung. Wenn Sie einfache Probleme in diesem Bereich nicht lösen können, werden Sie viel mehr kämpfen als nötig.
Glücklicherweise ist es nicht allzu schwierig, dies zu lernen. In diesem Artikel erfahren Sie, wie Sie mit Python, C++ und JavaScript einfache Zinsen und Zinseszinsen berechnen.
Wie berechnet man einfache Zinsen?
Der einfache Zins ist eine Methode zur Berechnung des Zinsbetrags, der auf einen Hauptbetrag zu einem bestimmten Zinssatz und für einen bestimmten Zeitraum erhoben wird. Sie können den einfachen Zins berechnen, indem Sie die folgende Formel verwenden:
Simple Interest = (P x R x T)/100
Where,
P = Principle Amount
R = Rate
T = Time
Die Problemstellung
Sie erhalten den Hauptbetrag , den Zinssatz und die Zeit . Sie müssen die einfachen Zinsen für die angegebenen Werte berechnen und drucken. Beispiel : Let Prinzip = 1000, Rate = 7 und timePeriod = 2. Simple Interest = (Prinzip * Rate * timePeriod) / 100 = (1000 * 7 * 2) / 100 = 140. Somit ist die Ausgabe 140.
Das C++-Programm zur Berechnung einfacher Zinsen
Unten ist das C++-Programm zur Berechnung von einfachen Zinsen:
// C++ program to calculate simple interest
// for given principle amount, time, and rate of interest.
#include <bits/stdc++.h>
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;
}
Ausgabe:
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
Das Python-Programm zur Berechnung einfacher Zinsen
Unten ist das Python-Programm, um einfache Zinsen zu berechnen:
# 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))
Ausgabe:
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
Das JavaScript-Programm zur Berechnung einfacher Zinsen
Unten ist das JavaScript-Programm, um einfache Zinsen zu berechnen:
// 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" + "<br>");
document.write("Principle amount: " + principle1 + "<br>");
document.write("Rate of interest: " + rate1 + "<br>");
document.write("Time period: " + timePeriod1 + "<br>");
document.write("Simple Interest: " + calculateSimpleInterest(principle1, rate1, timePeriod1) + "<br>");
var principle2 = 5000;
var rate2 = 5;
var timePeriod2 = 1;
document.write("Test case: 2" + "<br>");
document.write("Principle amount: " + principle2 + "<br>");
document.write("Rate of interest: " + rate2 + "<br>");
document.write("Time period: " + timePeriod2 + "<br>");
document.write("Simple Interest: " + calculateSimpleInterest(principle2, rate2, timePeriod2) + "<br>");
var principle3 = 5800;
var rate3 = 4;
var timePeriod3 = 6;
document.write("Test case: 3" + "<br>");
document.write("Principle amount: " + principle3 + "<br>");
document.write("Rate of interest: " + rate3 + "<br>");
document.write("Time period: " + timePeriod3 + "<br>");
document.write("Simple Interest: " + calculateSimpleInterest(principle3, rate3, timePeriod3) + "<br>");
Ausgabe:
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
So berechnen Sie den Zinseszins
Der Zinseszins ist die Aufstockung der Zinsen auf den Kapitalbetrag. Mit anderen Worten: Zinsen über Zinsen. Sie können den Zinseszins berechnen, indem Sie die folgende Formel verwenden:
Amount= P(1 + R/100)T
Compound Interest = Amount – P
Where,
P = Principle Amount
R = Rate
T = Time
Die Problemstellung
Sie erhalten den Hauptbetrag , den Zinssatz und die Zeit . Sie müssen den Zinseszins für die angegebenen Werte berechnen und drucken. Beispiel : Let Prinzip = 1000, Rate = 7 und timePeriod = 2. Betrag = P(1 + R/100)T = 1144,9 Zinseszins = Betrag – Prinzip Betrag = 1144,9 – 1000 = 144,9 Somit ist die Ausgabe 144,9.
Das C++-Programm zur Berechnung des Zinseszinses
Unten ist das C++-Programm zur Berechnung des Zinseszinses:
// C++ program to calculate compound interest
// for given principle amount, time, and rate of interest.
#include <bits/stdc++.h>
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;
}
Ausgabe:
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
Das Python-Programm zur Berechnung des Zinseszinses
Unten ist das Python-Programm zur Berechnung des Zinseszinses:
# 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))
Ausgabe:
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
Das JavaScript-Programm zur Berechnung des Zinseszinses
Unten ist das JavaScript-Programm zur Berechnung des Zinseszinses:
// 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" + "<br>");
document.write("Principle amount: " + principle1 + "<br>");
document.write("Rate of interest: " + rate1 + "<br>");
document.write("Time period: " + timePeriod1 + "<br>");
document.write("Compound Interest: " + calculateCompoundInterest(principle1, rate1, timePeriod1) + "<br>");
var principle2 = 5000;
var rate2 = 5;
var timePeriod2 = 1;
document.write("Test case: 2" + "<br>");
document.write("Principle amount: " + principle2 + "<br>");
document.write("Rate of interest: " + rate2 + "<br>");
document.write("Time period: " + timePeriod2 + "<br>");
document.write("Compound Interest: " + calculateCompoundInterest(principle2, rate2, timePeriod2) + "<br>");
var principle3 = 5800;
var rate3 = 4;
var timePeriod3 = 6;
document.write("Test case: 3" + "<br>");
document.write("Principle amount: " + principle3 + "<br>");
document.write("Rate of interest: " + rate3 + "<br>");
document.write("Time period: " + timePeriod3 + "<br>");
document.write("Compound Interest: " + calculateCompoundInterest(principle3, rate3, timePeriod3) + "<br>");
Ausgabe:
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
Kostenlos programmieren lernen: Beginnen Sie mit einfachen Zinsen und Zinseszinsen
Heutzutage nimmt die Bedeutung der Codierung exponentiell zu. Und damit einhergehend steigt auch die Nachfrage nach kompetenten Programmierern exponentiell. Es gibt ein Missverständnis unter den Leuten, dass sie das Programmieren nur lernen können, wenn sie eine hohe Gebühr bezahlen. Das stimmt aber nicht. Sie können von Plattformen wie freeCodeCamp, Khan Academy, YouTube usw. lernen, absolut kostenlos zu programmieren. Selbst wenn Sie kein großes Budget haben, müssen Sie sich keine Sorgen machen, etwas zu verpassen.