备案 几个网站,网页设计大作业模板,新人写手适合哪个平台,wordpress免费采集插件等额本金#xff0c;等额本息数学推导:贷款 买房#xff0c;利息怎么算#xff1f;不要被忽悠了#xff01;李永乐老师讲等额本金和等额本息
一个心血来潮的研究#xff0c;避免以后买房被坑。
捣鼓了半天才发现原来支付宝的那个利率是年利率不是月利率#xff0c;坑了…等额本金等额本息数学推导:贷款 买房利息怎么算不要被忽悠了李永乐老师讲等额本金和等额本息
一个心血来潮的研究避免以后买房被坑。
捣鼓了半天才发现原来支付宝的那个利率是年利率不是月利率坑了我半天。。。
代码
#include stdio.h
#include math.h
/*** description: 等额本金* param {double} totalPrincipal 贷款总额* param {int} years 按揭年数* param {double} annualInterestRate 年利率* return {*}*/
double EqualPrincipalPayment(double totalPrincipal, int years, double annualInterestRate)
{ annualInterestRate annualInterestRate / 100.0;int period years * 12;double monthlyInterestRate annualInterestRate / 12.0;double monthlyInterestPayment totalPrincipal * annualInterestRate;double monthlyPrincicalPayment totalPrincipal / period;double remainingPrincical totalPrincipal;printf(贷款方式等额本金\n);printf(贷款总额: %.02f\n, totalPrincipal);printf(年利率: %.02f%%\n, annualInterestRate * 100);printf(贷款期限: %d 年\n, years);int count 1;do{monthlyInterestPayment remainingPrincical * monthlyInterestRate;remainingPrincical - monthlyPrincicalPayment;double monthlyPayment monthlyPrincicalPayment monthlyInterestPayment;printf(期数: %6d | 剩余本金: %10.02f | 月供: %10.02f | 月供本金: %10.02f | 月供利息: %10.02f\n, count, remainingPrincical, monthlyPayment, monthlyPrincicalPayment, monthlyInterestPayment);count;} while (count period);
}// 等额本息
/*** description:* param {double} principal 贷款总额* param {int} years 按揭年数* param {double} annualInterestRate 年利率* return {*}*/
void EqualMonthlyPayment(double totalPrincipal, int years, double annualInterestRate) {annualInterestRate annualInterestRate / 100.0;int period years * 12;double monthlyInterestRate annualInterestRate / 12.0;//月付推导过程可见https://www.jianshu.com/p/168ffe04ac20double monthlyPayment totalPrincipal * (monthlyInterestRate * pow(1 monthlyInterestRate, period)) / (pow(1 monthlyInterestRate, period) - 1);printf(贷款方式等额本息\n);printf(贷款总额: %.02f\n, totalPrincipal);printf(年利率: %.02f%%\n, annualInterestRate * 100);printf(贷款期限: %d 年\n, years);printf(每月还款金额: %.02f\n, monthlyPayment);double remainingPrincipal totalPrincipal;int count 1;do {double interestPayment remainingPrincipal * monthlyInterestRate;double principalPayment monthlyPayment - interestPayment;remainingPrincipal - principalPayment;printf(期数: %6d | 剩余本金: %10.02f | 月供: %10.02f | 月供本金: %10.02f | 月供利息: %10.02f\n, count, remainingPrincipal, monthlyPayment, principalPayment, interestPayment);count;} while (count period);
}int main()
{EqualPrincipalPayment(100000, 10, 5.0);EqualMonthlyPayment(100000, 10, 5.0);
}
测试
程序输出
贷款方式等额本金
贷款总额: 100000.00
年利率: 5.00%
贷款期限: 1 年
期数: 1 | 剩余本金: 91666.67 | 月供: 8750.00 | 月供本金: 8333.33 | 月供利息: 416.67
期数: 2 | 剩余本金: 83333.33 | 月供: 8715.28 | 月供本金: 8333.33 | 月供利息: 381.94
期数: 3 | 剩余本金: 75000.00 | 月供: 8680.56 | 月供本金: 8333.33 | 月供利息: 347.22
期数: 4 | 剩余本金: 66666.67 | 月供: 8645.83 | 月供本金: 8333.33 | 月供利息: 312.50
期数: 5 | 剩余本金: 58333.33 | 月供: 8611.11 | 月供本金: 8333.33 | 月供利息: 277.78
期数: 6 | 剩余本金: 50000.00 | 月供: 8576.39 | 月供本金: 8333.33 | 月供利息: 243.06
期数: 7 | 剩余本金: 41666.67 | 月供: 8541.67 | 月供本金: 8333.33 | 月供利息: 208.33
期数: 8 | 剩余本金: 33333.33 | 月供: 8506.94 | 月供本金: 8333.33 | 月供利息: 173.61
期数: 9 | 剩余本金: 25000.00 | 月供: 8472.22 | 月供本金: 8333.33 | 月供利息: 138.89
期数: 10 | 剩余本金: 16666.67 | 月供: 8437.50 | 月供本金: 8333.33 | 月供利息: 104.17
期数: 11 | 剩余本金: 8333.33 | 月供: 8402.78 | 月供本金: 8333.33 | 月供利息: 69.44
期数: 12 | 剩余本金: 0.00 | 月供: 8368.06 | 月供本金: 8333.33 | 月供利息: 34.72
贷款方式等额本息
贷款总额: 100000.00
年利率: 5.00%
贷款期限: 1 年
每月还款金额: 8560.75
期数: 1 | 剩余本金: 91855.92 | 月供: 8560.75 | 月供本金: 8144.08 | 月供利息: 416.67
期数: 2 | 剩余本金: 83677.90 | 月供: 8560.75 | 月供本金: 8178.02 | 月供利息: 382.73
期数: 3 | 剩余本金: 75465.81 | 月供: 8560.75 | 月供本金: 8212.09 | 月供利息: 348.66
期数: 4 | 剩余本金: 67219.51 | 月供: 8560.75 | 月供本金: 8246.31 | 月供利息: 314.44
期数: 5 | 剩余本金: 58938.84 | 月供: 8560.75 | 月供本金: 8280.67 | 月供利息: 280.08
期数: 6 | 剩余本金: 50623.67 | 月供: 8560.75 | 月供本金: 8315.17 | 月供利息: 245.58
期数: 7 | 剩余本金: 42273.85 | 月供: 8560.75 | 月供本金: 8349.82 | 月供利息: 210.93
期数: 8 | 剩余本金: 33889.25 | 月供: 8560.75 | 月供本金: 8384.61 | 月供利息: 176.14
期数: 9 | 剩余本金: 25469.70 | 月供: 8560.75 | 月供本金: 8419.54 | 月供利息: 141.21
期数: 10 | 剩余本金: 17015.08 | 月供: 8560.75 | 月供本金: 8454.62 | 月供利息: 106.12
期数: 11 | 剩余本金: 8525.23 | 月供: 8560.75 | 月供本金: 8489.85 | 月供利息: 70.90
期数: 12 | 剩余本金: -0.00 | 月供: 8560.75 | 月供本金: 8525.23 | 月供利息: 35.52等额本金 等额本息