zoukankan      html  css  js  c++  java
  • 复利计算3.0

    程序构造思路:

    第一点:在求复利计算中达到终值所需年份是利用穷举法计算1-100年间符合的时间,最终求出存款所需时间。

    第二点:在求复利计算中利用复利公式的逆推,求出年利率的公式。

    #include<stdio.h>
    #include<math.h>
    #include<stdlib.h>
    void YEAR()
    {
        int year,flat=0; 
        double P,F;
        double i;
        printf("请输入本利和:"); 
        scanf("%lf",&F); 
        printf("请输入复利次数(年):"); 
        scanf("%d",&year); 
        printf("请输入本金:"); 
        scanf("%lf",&P); 
        i=pow(F/P, 1.0/year)-1;
        printf("年利率为:%lf",i);
    }
    void time()
    {
        int n,flat=0; 
        double P,i,F; 
        printf("请输入本利和:"); 
        scanf("%lf",&F); 
        printf("请输入年回报率:"); 
        scanf("%lf",&i); 
        printf("请输入本金:"); 
        scanf("%lf",&P); 
        for(n=1;n<100;n++)    //穷举法求100年满足的计息期数
        {
            if((P*(pow((1+i),n)))>=F)
            {
                printf("计息期数:%d
    
    ",n);
                flat=1;
                break;
            }
        }
        if(flat==0)
            printf("在100年内没有符合计息期数!
    
    ");
        
    }
    void menu()
    {                                 
        puts("
    
    ");
        puts("		|******************************************************|");
        puts("		|                    利息计算系统                      |");
        puts("		|******************************************************|");
        puts("		|                    1: 复利计算                       |");
        puts("		|                    2: 单利计算                       |");
        puts("		|                    3: 逆推计算                       |");
        puts("		|                    4: 期数计算                       |");
        puts("		|                    5: 利率计算                       |");
        puts("		|                    0: 退出程序                       |");
        puts("		|******************************************************|");
        printf("请选择<1~5>:");
    }
    void Fuli()
    {
        int year;//year表示复利年限
        double p;//p表示本金
        double i;//i表示年利率
        double F;//表示复利后的终值
        int k;
        printf("请输入复利次数(年):");
        scanf("%d",&year);
        printf("
    请输入本金:");
        scanf("%lf",&p);
        printf("
    请输入年利率:");
        scanf("%lf",&i);
        for(k=1;k<=year;k++){
            F=p*(1+i);
            p=F;
        }
        printf("
    复利后的终值为:");
        printf("%.2lf",F);
        
    }
    void Danli()
    {
        int year;//year表示复利年限
        double p;//p表示本金
        double i;//i表示年利率
        double Fv;//表示复利后的终值
        printf("请输入复利次数(年):");
        scanf("%d",&year);
        printf("
    请输入本金:");
        scanf("%lf",&p);
        printf("
    请输入年利率:");
        scanf("%lf",&i);
        printf("
    单利后的终值为:");
        Fv=p*(1+i*year);
        printf("%.2lf",Fv);
    }
    void Nitui()
    {
        int Year;    
        double P,i;
        double S;
        double E,D=1;
        int l;
        printf("输入期待金额为:");
        scanf("%lf",&S);
        printf("
    请输入存储年限:");
        scanf("%d",&Year);        
        printf("
    请输入年利率:");
        scanf("%lf",&i);
        
        for(l=1;l<=Year;l++)
        {
            E=D*(1+i);
            D=E;
        }
        P=S/D;
        printf("
    应输入的本金为:");
        printf("%.2lf",P);
    }
    
    main(){
        int n;
        while(1)
        {
            menu();
            scanf("%d",&n);
            if(n==0) break;
            switch(n)
            {  
            case 1:
                Fuli(); break;
            case 2:
                Danli();break;
            case 3:
                Nitui();break;
            case 4:
                time();break;
            case 5:
                YEAR(); break;
            case 0:
                n=0;exit(0);
                
            }
        }    
        
    }


  • 相关阅读:
    线段树、最短路径、最小生成树、并查集、二分图匹配、最近公共祖先--C++模板
    数据结构中各种树
    你必须知道的基本位运算技巧(状压DP、搜索优化都会用到)
    memset为int型数组初始化问题
    Dev-C++添加代码格式化(format source code)工具Artistic Style
    让vs IIS Express支持本地静态Json文件
    什么是「供给侧改革」? 原标题:中央提的“供给侧改革”是啥意思?有谁能解说下吗?
    PowerDesigner用法和技巧
    php 调用 web Server(短信接口示例)
    sae相关配置
  • 原文地址:https://www.cnblogs.com/RSTART/p/5283037.html
Copyright © 2011-2022 走看看