C 语言计算复利程序

如何编写一个 C 语言计算复利程序,并附带示例。在进入示例之前,我将向您展示计算背后的公式。

未来复利 = 本金 * (1 + 利率) 的 年数 次方

上面的代码被称为“未来复利”,因为它同时包含了本金和复利。要计算复利,请使用以下公式:

复利 = 未来复利 – 本金

C 语言计算复利程序

程序允许用户输入本金、利率和年数。利用这些值,该程序使用上述指定公式计算复利和未来复利。

#include<stdio.h>
#include <math.h>
 
int main() 
{
   float PAmount, ROI, Time_Period, CIFuture, CI;
 
   printf("\nPlease enter the Principal Amount : \n");
   scanf("%f", &PAmount);
 
   printf("Please Enter Rate Of Interest : \n");
   scanf("%f", &ROI);
 
   printf("Please Enter the Time Period in Years : \n");
   scanf("%f", &Time_Period);
 
   CIFuture = PAmount * (pow(( 1 + ROI/100), Time_Period));
   CI = CIFuture - PAmount;
   
   printf("\nFuture Compound Interest for Principal Amount %.2f is = %.2f", PAmount, CIFuture);
   printf("\nCompound Interest for Principal Amount %.2f is = %.2f", PAmount, CI);
 
   return 0;
}
Program to Calculate Compound Interest