简易房贷⽉供计算器
下⾯是⽤C语⾔编写的简易房贷⽉供计算器,供参考。
#include "stdio.h"
#include "math.h"
int main()
{
double amountOfLoan,annualInterest,repaymentPeriod; //input
double monthlyPayments; //output
double monthlyInterest,numOfMonth,tmp; // intermediate variables
//Input
printf("n A simple loan calculatornn");
printf(" Please input amount of loan(¥):");
scanf("%lf",&amountOfLoan);
printf("n Please input annual interest(%%):");
scanf("%lf",&annualInterest);
printf("n Please input repayment period(years):");
scanf("%lf",&repaymentPeriod);
//calculate
monthlyInterest = annualInterest/100/12;
numOfMonth = repaymentPeriod*12;
tmp = pow(1+monthlyInterest,numOfMonth);
monthlyPayments = (amountOfLoan * tmp * monthlyInterest)/(tmp-1);
//output
printf("nn You need to repay ¥%.2f each month. Good luck!n",monthlyPayments);
return 0;
}
下⾯是⽤HTML、CSS和Javascript脚本语⾔写的⼀个简易贷款⽉供计算器,可以在浏览器中运⾏。HTML定义了⽹页元素,CSS定义了页
⾯样式,Javascript实现了核⼼的计算部分。Javascript⽚段(标签之间的代码)的实现思路
和上⾯写的C语⾔代码是相似的:先获取数据,然后借助数学库函数进⾏计算,最后输出结果。不同的是,这⾥从⽹页上的⽂本框获取数
据,结果也是显⽰到页⾯元素上。
JavaScript Loan Calculator Amount of the loan(¥): Annual interest(%): Repayment period(years): Approximate Payments: Monthly Payments: ¥ Total Payments: ¥ Total Interest: ¥
把上述代码复制到⼀个⽂本⽂档中,后缀名改为.html,双击即可在浏览器中运⾏。
本文发布于:2023-05-27 11:44:14,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/falv/fa/83/120805.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |