0317

4.利率这么低,复利计算收益都这么厉害了,如果拿100万元去买年报酬率10%的股票,若一切顺利,过多长时间,100万元就变成200万元呢? 

5.如果我希望在十年内将100万元变成200万元,应该找到报酬率在多少的投资工具来帮助我达成目标?如果想在5年后本金翻倍,报酬率就应至少为多少才行呢?

#include<math.h>

#include<stdio.h>
int a;
int n;
float h;
double b;
double f;
void fCalc()
{
printf("------------复利计算------------ ");
printf(" ");
printf(" 请输入本金:");
scanf("%lf",&b);
printf("请输入回报率:");
scanf("%f",&h);
printf("请输入年限:");
scanf("%d",&n);
f=b*pow(h+1,n);
printf(" 得到的复利=%lf",f);
}
void bCalc()
{
printf("------------本金计算------------ ");
printf(" 请输入复利:");
scanf("%lf",&f);
printf("请输入回报率:");
scanf("%f",&h);
printf("请输入年限:");
scanf("%d",&n);
b=f/pow(h+1,n);
printf(" 得到的本金=%lf",b);
}
void hCalc()
{
printf("------------回报率计算------------ ");
printf(" 请输入本金:");
scanf("%f",&b);
printf("请输入年限:");
scanf("%d",&n);
printf("请输入复利:");
scanf("%1f",&f);
h=pow(f/b,1/n)-1;
printf("得到的回报率=%f",h);
}
void nCalc()
{
printf("------------年限计算------------ ");
printf(" 请输入本金:");
scanf("%f",&b);
printf("请输入回报率:");
scanf("%f",&h);
printf("请输入复利:");
scanf("%1f",&f);
n=log(f/b)/log(1+h);
printf("得到的回报率=%d",n);
}
void main()
{
printf("请选择你的计算:");
printf(" 1、复利计算");
printf(" 2、本金计算");
printf(" 3、回报率计算");
printf(" 4、年限计算");
printf(" ");
printf(" 你的选择是:");
scanf("%d",&a);
switch(a)
{
case 1:
fCalc();
break;
case 2:
bCalc();
break;
case 3:
hCalc();
break;
case 4:
nCalc();
break;
}
}

原文地址:https://www.cnblogs.com/yaohai/p/5289596.html