複利 C 程式?


本文將透過編寫一個 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

更新日期:30-07-2019

881 次瀏覽

開啟您的 職業生涯

完成本課程以獲得認證

開始
廣告
© . All rights reserved.