📜  C复利计画(1)

📅  最后修改于: 2023-12-03 15:30:14.986000             🧑  作者: Mango

C复利计算器

简介

C复利计算器是一款基于C语言开发的复利计算工具,可以方便地帮助用户计算出稳健的财务增长方案。

特性
  • 支持本金、年利率、投资年限的自定义输入。
  • 支持按照固定或月复利方式计算,按月复利方式计算精度更高。
  • 支持输出逐年或逐月的收益率、本金、利息、总金额等详细信息。
  • 界面简洁美观,易于使用。
安装

本程序无需安装即可直接使用,只需要将源代码文件复制到C语言开发环境中,编译并运行即可。

使用

用户可以根据个人情况,自定义本金、年利率和投资年限,选择固定或月复利方式计算。计算结果将会输出该种方案的逐年或逐月的收益率、本金、利息、总金额等详细信息。

以下为示例代码:

#include <stdio.h>
#include <math.h>
 
int main()
{
  // 输入本金
  double principal;
  printf("请输入投资本金:");
  scanf("%lf", &principal);
 
  // 输入年利率
  double annual_rate;
  printf("请输入年利率:");
  scanf("%lf", &annual_rate);
 
  // 输入投资期限
  int year, month;
  printf("请输入投资时间:(年 月) ");
  scanf("%d %d", &year, &month);
  int month_total = year * 12 + month;
 
  // 输入计算方式
  int compute_type;
  printf("请选择计算方式:1.固定利率 2.月复利:");
  scanf("%d", &compute_type);
 
  // 计算并输出结果
  double total_money = principal;
  double rate = annual_rate / 100;
  if (compute_type == 1) {
    for (int i = 1; i <= year; i++) {
      total_money = total_money * (1 + rate);
      printf("%d年后,总金额为:%.2f 元,收益为:%.2f 元\n", i, total_money, total_money - principal);
    }
  } else if (compute_type == 2) {
    for (int i = 1; i <= month_total; i++) {
      double current_month_rate = pow((1 + rate), (1 / 12.0)) - 1;
      total_money = total_money * (1 + current_month_rate);
      printf("%d个月后,总金额为:%.2f 元,收益为:%.2f 元\n", i, total_money, total_money - principal);
    }
  } else {
    printf("无效的计算方式。\n");
  }
 
  return 0;
}
贡献者
  • 作者:XXX
  • 邮箱:xxx@xxx.com
许可证

本项目采用MIT许可证进行开源,详见LICENSE文件。