โจทย์
คำนวณจำนวนเงินหลังจากฝากเงินพร้อมดอกเบี้ยทบต้นเป็นปี
สูตร
M = (r/100) * t A = P * e^M P = เงินต้น (Principal) r = อัตราดอกเบี้ย (%) t = ระยะเวลา (ปี) A = จำนวนเงินสุทธิ
อัลกอริทึม
- ประกาศตัวแปร double
- รับ P, r, t
- คำนวณ M = (r/100) * t
- คำนวณ A = P * exp(M) // ต้อง include
- แสดงผล
โปรแกรมตัวอย่าง
#include <stdio.h>
#include <math.h>
int main() {
double P, r, t, A, M;
printf("Principal amount: ");
scanf("%lf", &P);
printf("Interest rate (%%): ");
scanf("%lf", &r);
printf("Years: ");
scanf("%lf", &t);
M = (r / 100.0) * t;
A = P * exp(M);
printf("Amount after %.1f years = %.2f\n", t, A);
return 0;
}
ผลลัพธ์
amount to be deposit in the bank: 50000 enter the rate of interest: 6.5 How many years you want to deposit: 5 amount after 5.0 years with interest is: 69201.53