#include <stdio.h>
#include <math.h>
#define M 999
int main()
{
        double benjin = 0.0;
        double lilv = 0.0;
        double yue_lilv = 0.0;
        int nianxian = 0;
        double benxi_a = 0.0;
        double lixi_a = 0.0;
        double benjin_yihuan[M] = {0.0}; /*第i个月已还本金*/
        double benjin_yu[M] = {0.0};
        int yue_a = 0;
        int i = 0;
        double yue_benjin[M] = {0.0};
        double yue_lixi[M] = {0.0};
        double yue_benxi = 0.0;
        printf("请输入本金 年利率 年限\n");
        scanf("%lf%lf%d", &benjin, &lilv, &nianxian);
        yue_a = nianxian * 12;
        yue_lilv = lilv / 1200;
        yue_benxi = benjin * yue_lilv * pow(1 + yue_lilv, yue_a) / (pow(1 + yue_lilv, yue_a) - 1);
        yue_lixi[0] = benjin * yue_lilv;
        yue_benjin[0] =  yue_benxi - yue_lixi[0];
        benjin_yu[0] = benjin - yue_benjin[0];
        benjin_yihuan[0] = yue_benjin[0];
        printf("第%d个月-应还本金%.2lf\t-应还利息%.2lf\t-剩余本金%.2lf\n", 1, yue_benjin[0], yue_lixi[0], benjin_yu[0]);
        for (i = 1; i < yue_a; ++i)
        {
                yue_lixi[i] = benjin_yu[i-1] * yue_lilv;
                yue_benjin[i] = yue_benxi - yue_lixi[i];
                benjin_yihuan[i] = benjin_yihuan[i-1] + yue_benjin[i];
                benjin_yu[i] = benjin - benjin_yihuan[i];
                printf("第%d个月-应还本金%.2lf\t-应还利息%.2lf\t-剩余本金%.2lf\n", i+1, yue_benjin[i], yue_lixi[i], benjin_yu[i]);
                lixi_a += yue_lixi[i];
        }
        benxi_a = lixi_a + benjin + yue_lixi[0];
        printf("总本金[%.2lf] 总利息[%.2lf] 总本金利息和[%.2lf]\n", benjin, lixi_a + yue_lixi[0], benxi_a);
        return 0;
}

View Code

 

版权声明:本文为leegoo原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/leegoo/archive/2013/11/01/3401905.html