c語言計算貸款,c語言計算貸款還清要幾個月

本文目錄一覽:

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);

}

這是我的答案,我覺得最佳答案對於學習第一章的朋友並不是很友好。

原創文章,作者:FNCF,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/137325.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
FNCF的頭像FNCF
上一篇 2024-10-04 00:17
下一篇 2024-10-04 00:17

相關推薦

  • AES加密解密算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES算法,並對實現過程進…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演着非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • Python被稱為膠水語言

    Python作為一種跨平台的解釋性高級語言,最大的特點是被稱為”膠水語言”。 一、簡單易學 Python的語法簡單易學,更加人性化,這使得它成為了初學者的入…

    編程 2025-04-29
  • Python計算貸款及優惠額

    本文將從以下幾個方面詳細闡述使用Python計算貸款及優惠額的方法: 一、貸款本金及利息的計算 要計算貸款的本金與利息,可以使用以下公式: total_money = princi…

    編程 2025-04-29
  • OpenJudge答案1.6的C語言實現

    本文將從多個方面詳細闡述OpenJudge答案1.6在C語言中的實現方法,幫助初學者更好地學習和理解。 一、需求概述 OpenJudge答案1.6的要求是,輸入兩個整數a和b,輸出…

    編程 2025-04-29
  • Python按位運算符和C語言

    本文將從多個方面詳細闡述Python按位運算符和C語言的相關內容,並給出相應的代碼示例。 一、概述 Python是一種動態的、面向對象的編程語言,其按位運算符是用於按位操作的運算符…

    編程 2025-04-29
  • Python語言由荷蘭人為中心的全能編程開發工程師

    Python語言是一種高級語言,很多編程開發工程師都喜歡使用Python語言進行開發。Python語言的創始人是荷蘭人Guido van Rossum,他在1989年聖誕節期間開始…

    編程 2025-04-28
  • Python語言設計基礎第2版PDF

    Python語言設計基礎第2版PDF是一本介紹Python編程語言的經典教材。本篇文章將從多個方面對該教材進行詳細的闡述和介紹。 一、基礎知識 本教材中介紹了Python編程語言的…

    編程 2025-04-28
  • Python語言實現人名最多數統計

    本文將從幾個方面詳細介紹Python語言實現人名最多數統計的方法和應用。 一、Python實現人名最多數統計的基礎 1、首先,我們需要了解Python語言的一些基礎知識,如列表、字…

    編程 2025-04-28
  • Python作為中心語言,在編程中取代C語言的優勢和挑戰

    Python一直以其簡單易懂的語法和高效的編碼環境而著名。然而,它最近的發展趨勢表明Python的使用範圍已經從腳本語言擴展到了從Web應用到機器學習等廣泛的開發領域。與此同時,C…

    編程 2025-04-28

發表回復

登錄後才能評論