Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Lập Trình C

Chương trình C cho lãi suất kép

Ở đây chúng ta sẽ xem cách lấy lãi suất kép bằng cách viết một chương trình C đơn giản. Logic rất dễ. Ở đây chúng ta cần một số tham số:

  • P - Số tiền gốc
  • R - Lãi suất
  • T - Thời gian

Công thức lãi suất kép như sau:

Chương trình C cho lãi suất kép

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));
}

Kết quả

Enter Princple amount, rate of interest, and time: 5000 7.5 3
Interest value: 6211.485352