生活随笔
收集整理的這篇文章主要介紹了
复利计算器3.0
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int selectmenu();
void fuli(); //復利
void danli(); //單利
void benjin(); //本金
void time(); //時間
void lilv(); //利率
void invest(); //定額定投
void average(); //等額還款金額
void exit(); //退出
void main() //主函數
{
int choice;
choice=selectmenu();
while(1)
{
switch(choice)
{
case 1:
fuli();
break;
case 2:
danli();
break;
case 3:
benjin();
break;
case 4:
time();
break;
case 5:
lilv();
break;
case 6:
invest();
break;
case 7:
average();
break;
case 8:
exit(0);
break;
}
choice=selectmenu();
}
}
int selectmenu() //菜單
{
int choice;
printf(" 歡迎使用復利計算軟件
");
printf("
");
printf("功能菜單:
");
printf(" 1.計算復利終值
");
printf(" 2.計算單利終值
");
printf(" 3.計算本金
");
printf(" 4.計算時間
");
printf(" 5.計算利率
");
printf(" 6.年金終值(年|月)
");
printf(" 7.計算每月等額本息和
");
printf(" 8.退出
");
printf("
");
printf("please enter your choise(1--8):");
while( (!(scanf("%d",&choice)))|| (choice<1)||
(choice>8))
{
printf("
選擇錯誤,請重新選擇:
");
printf("
");
printf("功能菜單:
");
printf(" 1.計算復利終值
");
printf(" 2.計算單利終值
");
printf(" 3.計算本金
");
printf(" 4.計算時間
");
printf(" 5.計算利率
");
printf(" 6.年金終值(年|月)
");
printf(" 7.計算每月等額本息和
");
printf(" 8.退出
");
printf("
");
printf("please enter your choise(1--
8):");
}
return choice;
}
void tip() //計算公式
{
printf(" 復利計算公式
");
printf(" F=P*(1+i)N(次方)
");
printf(" 單利計算公式
");
printf(" I=P*i*N
");
printf(" 本金計算公式
");
printf(" P=F*(1+i)N(次方)
");
printf(" 時間計算公式
");
printf(" N=(int)(log(F/P)/log(1+i/m)/m)
");
printf(" 利率計算公式
");
printf(" i=m*(pow(F/P,1.0/(N*m))-1)
");
printf(" 每月等額本息和計算公式
");
printf(" P=F*i/(12*(1+i)*(pow(1+i,N)-1))
");
printf(" F:終值
");
printf(" P:本金
");
printf(" i:利率
");
printf(" N:計息期數
");
}
void fuli() //復利
{
int N,m;
double i,F,P;
tip();
printf("存入本金:");
scanf("%lf",&P);
printf("年利率:");
scanf("%lf",&i);
printf("存入年限:");
scanf("%d",&N);
printf("年復利次數:");
scanf("%d",&m);
F=P*pow((1+i/m),N*m);
printf("終值:%.4lf
",F);
}
void danli() //單利
{
int N;
double i,F,P;
tip();
printf("存入本金:");
scanf("%lf",&P);
printf("年利率:");
scanf("%lf",&i);
printf("存入年限:");
scanf("%d",&N);
F=P*i*N;
printf("終值:%.4lf
",F);
}
void benjin() //本金
{
int N,m;
double i,F,P;
tip();
printf("終值:");
scanf("%lf",&F);
printf("年利率:");
scanf("%lf",&i);
printf("存入年限:");
scanf("%d",&N);
printf("年復利次數:");
scanf("%d",&m);
P=F/pow((1+i/m),N*m);
printf("本金:%.4lf
",P);
}
void time() //時間
{
int N,m;
double i,F,P;
tip();
printf("存入本金:");
scanf("%lf",&P);
printf("年利率:");
scanf("%lf",&i);
printf("年復利次數:");
scanf("%d",&m);
printf("終值:");
scanf("%lf",&F);
N=(int)(log(F/P)/log(1+i/m)/m);
printf("時間:%d
",N);
}
void lilv() //利率
{
int N,m;
double i,F,P;
tip();
printf("存入本金:");
scanf("%lf",&P);
printf("存入年限:");
scanf("%d",&N);
printf("年復利次數:");
scanf("%d",&m);
printf("終值:");
scanf("%lf",&F);
i=m*(pow(F/P,1.0/(N*m))-1);
printf("利率:%.4lf
",i);
}
void invest()//計算年金終值
{
int N,n;
double i,F,P;
printf("存入本金:");
scanf("%lf",&P);
printf("存入年限:");
scanf("%d",&N);
printf("年利率:");
scanf("%lf",&i);
printf("1:按年投資
2:按月投資
");
A:printf("請選擇你要的功能<1|2>:");
scanf("%d",&n);
if(n==1)
{
F=P*(pow(1+i,N)-1)/i;
}
else if(n==2)
{
F=N*12*(P*(i/12)+P);
}
else
{
printf("輸入有誤!請重新輸入
");
goto A;
}
printf("%d年后的總產值:%.4lf
",N,F);
}
void average() //計算等額還款金額
{
int N;
double i,F,P;
printf("貸款金額:");
scanf("%lf",&F);
printf("存入年限:");
scanf("%d",&N);
printf("年利率:");
scanf("%lf",&i);
P=F*i/(12*(1+i)*(pow(1+i,N)-1));
printf("等額還款金額%.4lf
",P);
}
void exit() //退出
{
printf(" 感謝您使用復利計算軟件!
");
exit(0);
}
總結
以上是生活随笔為你收集整理的复利计算器3.0的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。