ที่นี่เราจะดูวิธีคำนวณดอกเบี้ยทบต้นด้วยโปรแกรม C ตรรกะง่าย ต้องมีพารามิเตอร์:
- P - เงินต้น (Principal)
- R - อัตราดอกเบี้ย (Rate)
- T - ระยะเวลา (Time)
สูตรดอกเบี้ยทบต้น:

ตัวอย่างโค้ด (C)
#include <stdio.h>
#include <math.h>
float compoundInterest(float P, float T, float R) {
return P * (pow(1 + (R/100), T));
}
int main() {
float p, t, r;
printf("Enter Principal amount, rate of interest, and time: ");
scanf("%f%f%f", &p, &r, &t);
printf("Interest value: %f", compoundInterest(p, t, r));
}
ผลลัพธ์
Enter Principal amount, rate of interest, and time: 5000 7.5 3 Interest value: 6211.485352