EMI (Equated Monthly Installment) คืออะไร?
EMI ย่อมาจาก Equated Monthly Installment คือ จำนวนเงินผ่อนชำระรายเดือนที่เท่ากันทุกงวด โปรแกรมนี้จะคำนวณค่าผ่อนชำระรายเดือนจากเงินต้น อัตราดอกเบี้ย และระยะเวลา
สูตรการคำนวณ EMI
EMI = (P × R × (1+R)ᵀ) / ((1+R)ᵀ - 1)
โดยที่:
- P = เงินต้น (Principal amount)
- R = อัตราดอกเบี้ยต่อเดือน (รายปี / 12 / 100)
- T = ระยะเวลาผ่อนชำระเป็นเดือน (ปี × 12)
ตัวอย่าง
Input: principal = 2000, rate = 5%, time = 4 ปี Output: Monthly EMI is = 46.058037
อัลกอริทึม
- รับค่า principal, rate, time
- แปลงอัตราดอกเบี้ยเป็นรายเดือน: r = rate / (12 * 100)
- แปลงระยะเวลาเป็นเดือน: t = time * 12
- คำนวณ EMI ตามสูตร
- แสดงผล
โค้ดภาษา C
#include <math.h>
#include <stdio.h>
float calculate_EMI(float p, float r, float t) {
float emi;
r = r / (12 * 100); // อัตราดอกเบี้ยต่อเดือน
t = t * 12; // ระยะเวลาเป็นเดือน
emi = (p * r * pow(1 + r, t)) / (pow(1 + r, t) - 1);
return emi;
}
int main() {
float principal = 2000, rate = 5, time = 4, emi;
emi = calculate_EMI(principal, rate, time);
printf("\nMonthly EMI is= %f\n", emi);
return 0;
}ผลลัพธ์
Monthly EMI is= 46.058037