zoukankan      html  css  js  c++  java
  • 0320-复利实验代码改进

    #include<stdio.h>
    #include<math.h>
    void Jisuan();
    double p,i,f;
    int n;
    void Danli()
    {
    printf("请输入本金:");
    scanf("%lf",&p);
    printf("请输入年利率(百分比):");
    scanf("%lf",&i);
    printf("请输入存储年限:");
    scanf("%d",&n);
    f = p+p*(i/100)*n;
    printf("单利终值为:%0.2lf ",f);
    }

    void Fuli()
    {
    printf("请输入本金:");
    scanf("%lf",&p);
    printf("请输入年利率(百分比):");
    scanf("%lf",&i);
    printf("请输入存储年限:");
    scanf("%d",&n);
    f = p*(pow(1+i/100,n));
    printf("复利终值为:%0.2lf ",f);
    }

    void Need()
    {
    printf("请输入目标金额:");
    scanf("%lf",&f);
    printf("请输入目标利率(百分比):");
    scanf("%lf",&i);
    printf("请输入目标年限:");
    scanf("%d",&n);
    p = f/pow(1+(i/100),n);
    printf("需要投入的本金为:%0.2lf ",p);
    }

    void Year()
    {
    printf("请输入本利和:");
    scanf("%lf",&f);
    printf("请输入年回报率(百分比):");
    scanf("%lf",&i);
    printf("请输入本金:");
    scanf("%lf",&p);
    for(n=1;;n++) //穷举法求100年满足的计息期数
    {
    if((p*(pow((1+i/100),n)))>=f)
    {
    printf("最低年限为:%d ",n);
    break;
    }
    }
    }

    void YearRate()
    {
    printf("请输入本利和:");
    scanf("%lf",&f);
    printf("请输入本金:");
    scanf("%lf",&p);
    printf("请输入目标年限:");
    scanf("%d",&n);
    i = pow((f/p),1.0/n)-1;
    printf("年回报率为:%0.2lf ",i);
    }

    void Getgains()
    {
    printf("请输入每年定投金额:");
    scanf("%lf",&p);
    printf("请输入年收益(百分比):");
    scanf("%lf",&i);
    printf("请输入定投年数:");
    scanf("%d",&n);
    f = p*(1+i/100)*(pow((1+i/100),n)-1)/(i/100);
    printf("基金定投收益为:%0.2lf ",f);
    }

    main()
    {

    int num=0;
    while(1){
    printf(" |************复利计算器************| ");
    printf(" |------------1.单利----------------| ");
    printf(" |------------2.复利----------------| ");
    printf(" |------------3.计算本金------------| ");
    printf(" |------------4.年限估算------------| ");
    printf(" |------------5.估算年回报率--------| ");
    printf(" |------------6.定额定投收益计算----| ");
    printf(" |----------------------------------| ");
    printf("请输入选择:");
    scanf("%d",&num);
    switch(num)
    {
    case 1:
    Danli();
    break;
    case 2:
    Fuli();
    break;
    case 3:
    Need();
    break;
    case 4:
    Year();
    break;
    case 5:
    YearRate();
    break;
    case 6:
    Getgains();
    break;
    default:
    return 0;
    }
    }
    }

  • 相关阅读:
    Android 黑科技保活实现原理揭秘
    Flutter +携程=?
    图解设计模式-Prototype模式
    图解设计模式-Singleton模式
    比较B-tree索引与Hash索引
    类元数据Class Metadata
    DriverManager类
    XMLMapperBuilder类
    PooledDataSource类
    Java并发编程的艺术(笔记)
  • 原文地址:https://www.cnblogs.com/55fmj/p/5299128.html
Copyright © 2011-2022 走看看