ที่นี่เราจะมาดูวิธีการรับดอกเบี้ยทบต้นโดยการเขียนโปรแกรม C หนึ่งโปรแกรม ตรรกะเป็นเรื่องง่ายมาก เราต้องการพารามิเตอร์บางอย่าง -
- P – จำนวนหลักการ
- R – อัตราดอกเบี้ย
- T - ช่วงเวลา
สูตรดอกเบี้ยทบต้นมีดังนี้

ตัวอย่าง
#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 Princple amount, rate of interest, and time: ");
scanf("%f%f%f", &p, &r, &t);
printf("Interest value: %f", compoundInterest(p, t, r));
} ผลลัพธ์
Enter Princple amount, rate of interest, and time: 5000 7.5 3 Interest value: 6211.485352