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

    6.如果每年都将积蓄的3万元进行投资,每年都能获得3%的回报,然后将这些本利之和连同年金再投入新一轮的投资,那么,30年后资产总值将变为多少?如果换成每月定投3000呢?

    (定额定投收益计算办法)

    8. 如果向银行贷款10万元,年利率6.5%,期限为10年,那么每月等额本息还款多少?(算复利条件下等额还款金额)
      1 #include<stdio.h>
      2 #include<math.h>
      3 int year,n;
      4 double p,q,F=0.0;
      5 void innit()
      6 {
      7     printf("注释:p为现金
    ");
      8     printf(" year为年限
    ");
      9     printf(" n为年复利次数
    ");
     10     printf(" q为年利率
    ");
     11     printf(" F为年复利终值
    ");
     12 }
     13 void menu()
     14 {
     15     printf("	|------------------------------------|
    ");
     16     printf("	|               welcome              |
    ");
     17     printf("	|------------------------------------|
    ");
     18     printf("	|          1、复利计算               |
    ");
     19     printf("	|          2、单利计算               |
    ");
     20     printf("	|          3、每月等额本息还款       |
    ");
     21     printf("	|          0、退出系统               |
    ");
     22     printf("	|------------------------------------|
    ");
     23 }
     24 //复利计算
     25 void compoundinterest(){
     26     int I,a;
     27     int ch;
     28 B:printf("	1、获取复利终值
    ");
     29   printf("	2、根据复利终值获取本金
    ");
     30   printf("	3、估算获得年终值的年限
    ");
     31   printf("	4、估算获得年终值的报酬率
    ");
     32   printf("	5、投资获利
    ");
     33   printf("请选择功能<1~5>:");
     34   scanf("%d",&I);
     35   if(I==1)
     36   {
     37       printf("请输入存款金额:");
     38       scanf("%lf",&p);
     39       printf("请输入存入存蓄年限:");
     40       scanf("%d",&year);
     41       printf("请输入年复利次数:");
     42       scanf("%d",&n);
     43       printf("请输入年利率:");
     44       scanf("%lf",&q);
     45       F=p*pow((1+q/n),year*n);
     46       printf("复利终值为%lf:",F);
     47   }
     48   if(I==2)
     49   {
     50       printf("请输入复利终值:");
     51       scanf("%lf",&F);
     52       printf("请输入存入存蓄年限:");
     53       scanf("%d",&year);
     54       printf("请输入年复利次数:");
     55       scanf("%d",&n);
     56       printf("请输入年利率:");
     57       scanf("%lf",&q);
     58       p=F/(pow((1+q/n),year*n));
     59       printf("复利本金为%lf:",p);
     60   }
     61   if(I==3)
     62   {
     63           printf("请输入存款金额:");
     64       scanf("%lf",&p);
     65       printf("请输入年利率:");
     66       scanf("%lf",&q);
     67       printf("请输入年复利次数:");
     68       scanf("%d",&n);
     69       printf("请输入年终值:");
     70           scanf("%lf",&F);
     71 
     72      year=(int)(log(F/p)/log(1+q/n))/n;
     73      // F=p*(1+q*year);
     74       printf("年限为%d
    :",year);
     75 
     76 
     77   }
     78   if(I==4)
     79   {
     80       printf("请输入存款金额:");
     81       scanf("%lf",&p);
     82       printf("请输入存入存蓄年限:");
     83       scanf("%d",&year);
     84       printf("请输入年复利次数:");
     85       scanf("%d",&n);
     86        printf("请输入年终值:");
     87           scanf("%lf",&F);
     88       //F=p*pow((1+q/n),year*n);
     89           q=n*(pow(F/p,1.0/(year*n))-1);
     90       printf("复利的年利率为%lf:
    ",year,q);
     91 
     92   }
     93   if(I==5)
     94   {
     95       printf("1.按月投   2.按年投
    ");
     96           printf("请选择定投方式:");
     97           scanf("%d",&a);
     98           if(a==1){
     99               printf("请输入月投金额:");
    100               scanf("%lf",&p);
    101               printf("请输入存入定投年限:");
    102               scanf("%d",&year);
    103               printf("请输入收益率:");
    104               scanf("%lf",&q);
    105             F=p*12*(1+q)*(-1+pow(1+q,year))/q;
    106             printf("%d年后的资产终值为:%lf",year,F);}
    107           if(a==2){
    108               printf("请输入年投金额:");
    109               scanf("%lf",&p);
    110               printf("请输入存入定投年限:");
    111               scanf("%d",&year);
    112               printf("请输入收益率:");
    113               scanf("%lf",&q);
    114             F=p*(1+q)*(-1+pow(1+q,year))/q;
    115             printf("%d年后的资产终值为:%lf",year,F);}
    116 
    117   }
    118        
    119   printf("
    	是否要重新计算?(1/0)
    ");
    120   scanf("%d",&ch);
    121   if(ch==1)
    122   {
    123       goto B;
    124   }
    125 }
    126 
    127 //单利计算
    128 void simpleinterest()
    129 {
    130     int n;
    131     int ch;
    132 A:printf("	1、获取单利终值
    ");
    133   printf("	2、根据单利终值获取本金
    ");
    134   printf("	3、估算获得年终值的年限
    ");
    135   printf("	4、估算获得年终值的报酬率
    ");
    136   printf("请选择功能<1~4>:");
    137   scanf("%d",&n);
    138   if(n==1)
    139   {
    140       
    141       printf("请输入存款金额:");
    142       scanf("%lf",&p);
    143       printf("请输入存入存蓄年限:");
    144       scanf("%d",&year);
    145       printf("请输入年利率:");
    146       scanf("%lf",&q);
    147       
    148       F=p*(1+q*year);
    149       printf("单利终值为%lf
    :",F);}
    150   if(n==2)
    151   {
    152       printf("请输入单复利终值:");
    153       scanf("%lf",&F);
    154       printf("请输入存入存蓄年限:");
    155       scanf("%d",&year);
    156       printf("请输入年利率:");
    157       scanf("%lf",&q);
    158       
    159       p=F/(1+q*year);
    160       printf("本金为%lf
    :",p);}
    161   if(n==3){
    162 
    163           printf("请输入存款金额:");
    164       scanf("%lf",&p);
    165       printf("请输入年利率:");
    166       scanf("%lf",&q);
    167       
    168       printf("请输入年终值:");
    169           scanf("%lf",&F);
    170 
    171      year=(int)((F/p-1)/q);
    172      // F=p*(1+q*year);
    173       printf("年限为%d
    :",year);
    174 
    175   }
    176   if(n==4){
    177       printf("请输入存款金额:");
    178       scanf("%lf",&p);
    179       printf("请输入存入存蓄年限:");
    180       scanf("%d",&year);
    181        printf("请输入年终值:");
    182           scanf("%lf",&F);
    183       //F=p*pow((1+q/n),year*n);
    184           q=(F/p-1)/year;
    185       printf("单利的年利率为%lf:
    ",q);
    186 
    187 
    188   }  
    189 
    190   printf("
    	是否要重新计算?(1/0)
    ");
    191   scanf("%d",&ch);
    192   if(ch==1)
    193   {
    194       goto A;
    195 }}
    196 
    197 
    198 void DengEHuanKuan(){
    199      printf("请输入贷款金额:");
    200               scanf("%lf",&F);
    201               printf("请输入存入贷款年限:");
    202               scanf("%d",&year);
    203               printf("请输入年利率:");
    204               scanf("%lf",&q);
    205             p=F*q/(12*(1+q)*(-1+pow(1+q,year)));
    206             printf("每月等额本息还款为:%lf
    ",p);
    207 }
    208 
    209 
    210 
    211 main(){
    212     int ch,n;
    213     while(1){
    214         if(n==0) break;
    215         innit();
    216         menu();
    217         printf("
    ");
    218         printf("please chose<0~4>:");
    219         scanf("%d",&ch);
    220         switch(ch){
    221         case 1:compoundinterest();break;
    222         case 2:simpleinterest();break;
    223         case 3:DengEHuanKuan();break;
    224         case 0:n=0;break;
    225 }}}
    226 //基金定投收益计算公式:
    227 //M=a(1+x)[-1+(1+x)^n]/x
    228 //M:预期收益
    229 //a:每期定投金额
    230 //x:收益率
    231 //n:定投期数(公式中为n次方)
    232 //注意a、x和n的匹配,月定投金额、月收益率、定投月数,如果是年,统一以后再计算。
    233 //假设每月定投300元(每年为3600),年收益15%,定投35年。


    运行结果:

  • 相关阅读:
    watchguard 软件工程师内部招聘!
    反脆弱:被雅虎裁掉的为何是他们?
    Linux SSH无密码login
    Makefile选项CFLAGS,LDFLAGS,LIBS
    python 相关编码[转]
    用python处理html代码的转义与还原
    运维部_首席架构师
    Software Engineer(百赴美)
    修改linux文件权限命令:chmod
    How to install Eclipse?
  • 原文地址:https://www.cnblogs.com/4249ken/p/5295951.html
Copyright © 2011-2022 走看看