匿名使用者
匿名使用者 發問時間: 電腦與網際網路程式設計 · 1 0 年前

急!c語言 房屋貸款利率的計算

題目:

某人向銀行

貸款X元..

利息Y%..

Z年還完..

請問一個月要付多少錢 ?

上述的x y z 都要可以自由輸入

用c語言完成

請各位大大幫幫忙

已更新項目:

可以附上程式碼的解釋嗎??

尤其是這一行

payment = ( amount * ( pow( 1.f + interest, float(year) ) ) ) / float(year * 12);

2 個解答

評分
  • 1 0 年前
    最佳解答

    /*

    this is for compound interest calculation. ask if you need linear interest or mortgage calculation. also, this is in c++, but i am sure you can convert them to C pretty easily

    */

    #include <iostream> // cin, cout...

    #include <cmath> // pow

    using namespace std;

    int main(void)

    {

    float amount, interest, payment;

    int year;

    // no error check, assuming users are not idiots

    cout << "Enter loan amount: ";

    cin >> amount;

    cout << "\n";

    cout << "Enter interest: ";

    cin >> interest;

    cout << "\n";

    cout << "Loan duration (in years): ";

    cin >> year;

    cout << "\n";

    /* ****this is the equation to calculate compound interest***

    A = P( 1 + ( r / n ) )^( n * t )

    A = total amount

    P = loan amount

    t = numbers of loan year

    r = interest

    n = number of times the interest is compounded per year, in this case, 1

    */

    payment = ( amount * ( pow( 1.f + interest, float(year) ) ) ) / float(year * 12);

    cout << "Monthly payment: " << payment << "\n";

    return 0;

    }

    2007-05-01 03:48:43 補充:

    amount * ( pow( 1.f + interest, float(year) ) ) ->final amount calculation

    this is from this equation: A = P( 1 + ( r / n ) )^( n * t ) .

    divide by ( year * 12 = total months ) to calculate monthly payment.

  • 1 0 年前

    #include<stdio.h>

    int main(void)

    {

    double a,b,d;

    int i,c,e;

    printf("請輸入借貸金額\n");

    scanf("%lf",&a);

    printf("請輸入利息\n");

    scanf("%lf",&b);

    printf("請問要分期幾年\n") ;

    scanf("%ld",&c);

    b = (b/100); //年息

    for (i=c;i>=1;i--)

    {

    d = (a/i)+(a*b); //設定所要環款的金額 本金+利息

    printf("第%d年息%f\n",i,d);

    a = a-(a/i); //扣除所還本金

    }

    scanf("%lf",&a);

    return(0);

    }

    DEV c++ 這是最簡單的= =+

    參考資料: 自己
還有問題?馬上發問,尋求解答。