#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\n",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\n",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\n",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\n",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\n",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\n",f);
}

main()
{

int num=0;
while(1){
printf("\t\t\t|************复利计算器************|\n");
printf("\t\t\t|------------1.单利----------------|\n");
printf("\t\t\t|------------2.复利----------------|\n");
printf("\t\t\t|------------3.计算本金------------|\n");
printf("\t\t\t|------------4.年限估算------------|\n");
printf("\t\t\t|------------5.估算年回报率--------|\n");
printf("\t\t\t|------------6.定额定投收益计算----|\n");
printf("\t\t\t|----------------------------------|\n");
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;
}
}
}

posted on 2016-03-20 18:06  55冯铭杰  阅读(135)  评论(0编辑  收藏  举报