Ở đây chúng ta sẽ xem cách nhận lãi kép bằng cách viết một chương trình C. Logic là rất dễ dàng. Ở đây chúng tôi cần một số tham số -
- P - Số tiền nguyên tắc
- R - Lãi suất
- T - Khoảng thời gian
Công thức lãi kép như dưới đây
Ví dụ
#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));
} Đầu ra
Enter Princple amount, rate of interest, and time: 5000 7.5 3 Interest value: 6211.485352