#include<stdio.h> #include<math.h> double danli(double i,int N,double P) { double nlx,F; nlx = P*i; F = nlx*N + P; return F; } double fuli(double i,int W,int N,double P) { double F; i=pow(1+i/W,W)-1; F=P*pow((i+1),N); return F; } double gusuan(double i,int W,int N,double F) { double P; i = pow(1+i/W,W)-1; P = F/pow((i+1),N); return P; } double shijian(double P,double i,double F) { double N,x; x=F/P; N=(log(x))/(log(i+1)); return N; } double nianxian(double P,double N,double F) { double i; //i = W*(pow(pow(F/P,1.0/N),1.0/W)-1.0); i = pow(F/P,1.0/N)-1.0; return i; } void main() { double P,F1,F,i; //P是本金,F是收益,i年利率 int N,W,ch2; //是期限 while(1) { printf(" ***************欢迎使用复利计算器************* "); printf(" | -----1--------为复利--------------- | "); printf(" | -----2--------为单利--------------- | "); printf(" | -----3-------为估算---------------- | "); printf(" | -----4-------为年限---------------- | "); printf(" | -----5-------为年利率-------------- | "); printf(" | -----0-------为退出---------------- | "); printf("请选择 "); scanf("%d",&ch2);//控制选择 switch(ch2){ case 1: printf("请输入本金: "); scanf("%lf",&P); printf("请输入年利率 "); scanf("%lf",&i); printf("请输入年限: "); scanf("%d",&N); printf("请输入复利次数: "); scanf("%d",&W); F1 = fuli(i,W,N,P); break; case 2: printf("请输入本金: "); scanf("%lf",&P); printf("请输入年利率 "); scanf("%lf",&i); printf("请输入年限: "); scanf("%d",&N); F1 = danli(i,N,P); break; case 3: printf("请输入本利 "); scanf("%lf",&F); printf("请输入年利率 "); scanf("%lf",&i); printf("请输入年限: "); scanf("%d",&N); printf("请输入复利次数: "); scanf("%d",&W); F1 = gusuan(i,W,N,F); break; case 4: printf("请输入本金 "); scanf("%lf",&P); printf("请输入年利率 "); scanf("%lf",&i); printf("请输入本利 "); scanf("%lf",&F); F1=shijian(P,i,F); break; case 5: printf("请输入本金: "); scanf("%lf",&P); printf("请输入本利: "); scanf("%lf",&F); printf("请输入年限 "); scanf("%d",&N); F1=nianxian(P,N,F); // i=pow((F/P),(1.0/N))-1; break; case 0:break; } if(ch2==0) break; printf("结果为:%.2lf ",F1); } }