简易房贷月供计算器

#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 calculator\n\n");
printf(" Please input amount of loan(￥):");
scanf("%lf",&amountOfLoan);
scanf("%lf",&annualInterest);
scanf("%lf",&repaymentPeriod);
//calculate
monthlyInterest = annualInterest/100/12;
numOfMonth = repaymentPeriod*12;
tmp = pow(1+monthlyInterest,numOfMonth);
monthlyPayments = (amountOfLoan * tmp * monthlyInterest)/(tmp-1);
//output
printf("\n\n You need to repay ￥%.2f each month. Good luck!\n",monthlyPayments);
return 0;
}

<!DOCTYPE html>
<html>
<title>JavaScript Loan Calculator</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
*{
margin:0;
}
body{
background-color:snow;
font-size:14pt;
}
.container{
width:70%;
height:1000px;
background-color:antiquewhite;
margin:0 auto;
}
.output{font-weight:bold;}
#payment{text-decoration:underline;}
table{
width:40%;
height:50%;
}
th,td{
vertical-align:center;
}
</style>
<body>
<div class="container">
<table align="center">
<tr>
<th colspan=2>JavaScript Loan Calculator</th>
</tr>
<tr>
<td>Amount of the loan(￥):</td>
<td><input id='amount' onchange='calculate();'></td>
</tr>
<tr>
<td>Annual interest(%):</td>
<td><input id='apr' onchange='calculate();'></td>
</tr>
<tr>
<td>Repayment period(years):</td>
<td><input id='years' onchange='calculate();'></td>
</tr>
<tr>
<td>Approximate Payments:</td>
<td><button onclick='calculate();'>Calculate</button></td>
</tr>
<tr>
<td>Monthly Payments:</td>
<td>￥<span class='output' id='payment'></span></td>
</tr>
<tr>
<td>Total Payments:</td>
<td>￥<span class='output' id='total'></span></td>
</tr>
<tr>
<td>Total Interest:</td>
<td>￥<span class='output' id='totalinterest'></span></td>
</tr>
</table>
</div>

<script type="text/javascript">
"use strict";
function $(id){ return document.getElementById(id); } function calculate () { var amount =$('amount');
var apr = $('apr'); var years =$('years');
var payment = $('payment'); var total =$('total');
var totalinterest = \$('totalinterest');

var principal = parseFloat(amount.value);
var interest = parseFloat(apr.value)/100/12;
var payments = parseFloat(years.value)*12;

var x = Math.pow(1+interest ,payments);
var monthly = (principal * x * interest)/(x-1);

if(isFinite(monthly))
{
payment.innerHTML = monthly.toFixed(2);
total.innerHTML = (monthly*payments).toFixed(2);
totalinterest.innerHTML = ((monthly*payments)-principal).toFixed(2);
}
}
</script>
</body>
</html>

05-13

11-19
10-17
03-17 1765
11-12 947
10-09 1172
03-04 3667
09-21 1034
09-13 1882
10-24 378
07-10 468
01-05 587
01-05 3515
01-16 51