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

Z年還完..

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++ 這是最簡單的= =+

參考資料： 自己