本文目录一览:
C语言计算贷款还款额怎么做?
等额本息还款,也称定期付息,即借款人每月按相等的金额偿还贷款本息,其中每月贷款利息按月初剩余贷款本金计算并逐月结清。把按揭贷款的本金总额与利息总
额相加,然后平均分摊到还款期限的每个月中。作为还款人,每个月还给银行固定金额,但每月还款额中的本金比重逐月递增、利息比重逐月递减。
每月等额还本付息额:
P:贷款本金
R:月利率
N:还款期数
其中:还款期数=贷款年限×12
每月还款的公式
例如:
计算贷款还款额。贷款一年利率为3%,一年到五年利率为4%,五年到10年利率为5%,10年以上为6%。要求编写程序实现,输入贷款额度和年限,输出每月还款额。
C源程序:
#include stdio.h
#include math.h
int main() {
int total, year;
double rate_year;
scanf("%d %d", total, year);
if(year = 1)
rate_year = 0.03;
else if(year = 5)
rate_year = 0.04;
else if(year = 10)
rate_year = 0.05;
else
rate_year = 0.06;
double rate = rate_year / 12;
printf("%lf\n", total*pow(rate+1,year*12)*rate/(pow(rate+1,year*12)-1));
return 0;
}
C++ C语言程序设计 题目:贷款计算器
/*
* main.c
*
* Created on: 2011-6-8
* Author: icelights
*/
#include stdio.h
#include stdlib.h
#include ctype.h
#include math.h
#define APR1 0.0747 /*1年(含1年)年利率*/
#define APR2 0.0756 /*1-3年(含3年)年利率*/
#define APR3 0.0774 /*3-5年(含5年)年利率*/
#define APR4 0.0783 /*5年以上年利率*/
#define A_TO_M 1/12 /*月利率 = 年利率 / 12*/
#define RTP 12 /*Reimbursement total periods还款总期数 =年限*12*/
#define LENGTH 80
struct LoanInfo
{
/*姓名*/
char name[LENGTH];
/*贷款总额*/
double LoanAmount;
/*贷款年限*/
double LoanYear;
/*月付*/
double MonthlyPayment;
/*总利息*/
double TotalInterest;
/*还款总额*/
double ReimbursementAmount;
/*年利率*/
double apr;
struct LoanInfo * next;
};
void CalcShow(struct LoanInfo * cur, struct LoanInfo * hd,
struct LoanInfo * prv);
int main(void)
{
int temp;
struct LoanInfo * head = NULL;
struct LoanInfo * prev, * current;
current = (struct LoanInfo *)malloc(sizeof(struct LoanInfo));
if (NULL == head)
{
head = current;
}
else
{
prev-next = current;
}/*End of if (NULL == head)*/
puts("请输入姓名");
gets(current-name);
fflush(stdin);
puts("请输入贷款数额(单位:万元)");
scanf("%lf", ¤t-LoanAmount);
fflush(stdin);
puts("请输入贷款年限");
scanf("%lf", ¤t-LoanYear);
fflush(stdin);
printf("姓名:%s,贷款年限:%lf, 贷款数额%lf",
current-name, current-LoanYear, current-LoanAmount);
prev = current;
puts("请确认Y/N");
temp = getchar();
switch(toupper(temp))
{
case 'Y' : CalcShow(current, head, prev);
break;
case 'N' : free(current);
main();
break;
default : puts("输入错误");
free(current);
break;
}
return 0;
}
void CalcShow(struct LoanInfo * cur, struct LoanInfo * hd,
struct LoanInfo * prv)
{
char lcv_temp;
if (cur-LoanYear = 1)
cur-apr = APR1;
else if (cur-LoanYear = 3)
cur-apr = APR2;
else if (cur-LoanYear = 5)
cur-apr = APR3;
else
cur-apr = APR4;
/*End of if (year = 1)*/
cur-LoanAmount = 10000 * cur-LoanAmount;
cur-ReimbursementAmount = cur-LoanAmount * pow((1 + cur-apr), cur-LoanYear);
cur-MonthlyPayment = cur-ReimbursementAmount / (cur-LoanYear * RTP);
cur-TotalInterest = cur-ReimbursementAmount - cur-LoanAmount;
printf("姓名:%s 贷款年限:%.0lf\n"
"贷款数额:%.2lf 每月还款额:%.2lf\n"
"利息合计:%.2lf 还款总额:%.2lf\n",
cur-name, cur-LoanYear, cur-LoanAmount,
cur-MonthlyPayment, cur-TotalInterest, cur-ReimbursementAmount);
puts("是否继续计算Y/N");
lcv_temp = getchar();
switch(toupper(lcv_temp))
{
case 'Y' : free(cur);
main();
break;
case 'N' : free(cur);
exit(0);
default : puts("输入错误");
free(cur);
main();
break;
}
system("pause");
}
请教C语言编程中计算还贷后剩余的贷款金额的详细答案, 最好能够说明一下每个步骤!
#include stdio.h
int main(void){
float amount,rate,payment,month_rate,tmp1,tmp2,tmp3;
printf("Enter amount of lean:");
scanf("%f",amount);
printf("Enter interest rate:");
scanf("%f",rate);
printf("Enter monthly payment:");
scanf("%f",payment);
month_rate = rate / 100.0f / 12.0f;
tmp1 = (amount-payment)+amount*month_rate;
tmp2 = (tmp1-payment)+tmp1*month_rate;
tmp3 = (tmp2-payment)+tmp2*month_rate;
printf("Balance remaining after first payment:%.2f\n",tmp1);
printf("Balance remaining after second payment:%.2f\n",tmp2);
printf("Balance remaining after third payment:%.2f\n",tmp3);
}
这是我的答案,我觉得最佳答案对于学习第一章的朋友并不是很友好。