#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);
}

main()
{
int num=0;
printf("\t\t\t|***********复利计算器************|\n");
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|---------------------------------|\n");
printf("请输入选择:");
scanf("%d",&num);
switch(num)
{
case 1:
Danli();
break;
case 2:
Fuli();
break;
case 3:
Need();
default:
return 0;
}
}

posted on 2016-03-16 10:38  55冯铭杰  阅读(123)  评论(0编辑  收藏  举报