단순 및 복리 이자를 계산하는 방법

단순 및 복리 이자를 계산하는 방법

수학은 프로그래밍의 필수적인 부분입니다. 이 영역에서 간단한 문제를 해결할 수 없다면 필요한 것보다 훨씬 더 많은 어려움을 겪을 것입니다.





다행히도 그렇게 하는 방법을 배우는 것은 그리 어렵지 않습니다. 이 기사에서는 Python, C++ 및 JavaScript를 사용하여 단리 및 복리를 계산하는 방법을 배웁니다.





Outlook 이메일을 Gmail로 전달하는 방법

단순이자를 어떻게 계산합니까?

단리법은 원금에 대해 정해진 이율로 일정 기간 동안 부과되는 이자를 계산하는 방법입니다. 다음 공식을 사용하여 단순 이자를 계산할 수 있습니다.





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

문제 설명

당신은 주어진 원금 , 이자율 , 그리고 시각 . 주어진 값에 대한 단순 이자를 계산하고 인쇄해야 합니다. 예시 : 원리 = 1000, rate = 7, timePeriod = 2로 둡니다. 단순이자 = (원칙 * rate * timePeriod) / 100 = (1000 * 7 * 2) / 100 = 140입니다. 따라서 출력은 140입니다.

단순 이자 계산을 위한 C++ 프로그램

다음은 단순이자 계산을 위한 C++ 프로그램입니다.



// 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;
}

산출:

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

관련: C++, Python 및 JavaScript에서 자연수의 모든 요소를 ​​찾는 방법





단순 이자 계산을 위한 Python 프로그램

다음은 단순이자를 계산하는 Python 프로그램입니다.

# 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))

산출:





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

관련된: 다양한 프로그래밍 언어로 FizzBuzz Challenge를 완료하는 방법

단순 이자를 계산하는 JavaScript 프로그램

다음은 단순이자를 계산하는 JavaScript 프로그램입니다.

// 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) + '
');

산출:

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

복리 이자를 계산하는 방법

복리는 원금에 이자를 더한 것입니다. 즉, 이자에 대한 이자입니다. 다음 공식을 사용하여 복리 이자를 계산할 수 있습니다.

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

문제 설명

당신은 주어진 원금 , 이자율 , 그리고 시각 . 주어진 값에 대한 복리 이자를 계산하고 인쇄해야 합니다. 예시 : 원리 = 1000, 비율 = 7, timePeriod = 2라고 합시다. 금액 = P(1 + R/100)T = 1144.9 복리 이자 = 금액 - 원리 금액 = 1144.9 - 1000 = 144.9 따라서 출력은 144.9입니다.

복리 이자를 계산하는 C++ 프로그램

다음은 복리 이자를 계산하는 C++ 프로그램입니다.

// 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;
}

산출:

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

관련된: C++, Python 및 JavaScript에서 배열을 뒤집는 방법

단어에 줄을 추가하는 방법

복리 이자를 계산하는 Python 프로그램

다음은 복리 이자를 계산하는 Python 프로그램입니다.

# 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))

산출:

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

관련된: 배열의 모든 요소의 합을 찾는 방법

복리 이자를 계산하는 JavaScript 프로그램

다음은 복리 이자를 계산하는 JavaScript 프로그램입니다.

// 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) + '
');

산출:

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

무료로 코딩 배우기: 단순 복리로 시작

오늘날 코딩의 영향력은 기하급수적으로 증가하고 있습니다. 이에 발맞추어 능숙한 코더에 대한 수요도 기하급수적으로 증가하고 있습니다. 높은 비용을 지불해야만 코딩을 배울 수 있다는 오해가 있다. 그러나 그것은 사실이 아닙니다. freeCodeCamp, Khan Academy, YouTube 등과 같은 플랫폼에서 완전 무료로 코딩을 배울 수 있습니다. 따라서 큰 예산이 없더라도 놓치는 것에 대해 걱정할 필요가 없습니다.

공유하다 공유하다 트위터 이메일 무료로 코딩하는 법을 배우는 7가지 최고의 방법

무료로 코딩을 배울 수는 없습니다. 물론 이러한 검증된 리소스를 제공하지 않는 한.

다음 읽기
관련 항목
  • 프로그램 작성
  • 파이썬
  • 자바스크립트
  • 코딩 튜토리얼
저자 소개 유브라지 찬드라(60편 게재)

Yuvraj는 인도 델리 대학교의 컴퓨터 공학 학부생입니다. 그는 풀 스택 웹 개발에 열정적입니다. 그는 글을 쓰지 않을 때 다양한 기술의 깊이를 탐구하고 있습니다.

유브라지 찬드라가 참여한 작품 더보기

뉴스레터 구독

기술 팁, 리뷰, 무료 전자책 및 독점 거래에 대한 뉴스레터에 가입하십시오!

구독하려면 여기를 클릭하세요.