Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 #include <stdio.h>
- 2 int main (void)
- 3 {
- 4 double loan_amount, loan_balance, total_interest;
- 5 double monthly_payment, monthly_interest_rate;
- 6 double interest_rate, interest_for_this_month, left_over_payment;
- 7
- 8 int years, month;
- 9
- 10 printf("How many years is your loan?: ");
- 11 scanf("%i", &years);
- 12
- 13 printf("Loan amount?: ");
- 14 scanf("%lf", &loan_amount);
- 15
- 16 printf("Annual interest rate in percent?: ");
- 17 scanf("%lf", &interest_rate);
- 18
- 19 printf("Monthly payment?: ");
- 20 scanf("%lf", &monthly_payment);
- 21
- 22 /* years = 30;
- 23 loan_amount = 200000;
- 24 interest_rate = 6;
- 25 monthly_payment = 1199.10;
- 26 */
- 27 monthly_interest_rate = interest_rate/100/12;
- 28 total_interest = 0.0;
- 29 loan_balance = loan_amount;
- 30
- 31 for(month = 1; month <= years*12; month++)
- 32 {
- 33 interest_for_this_month = monthly_interest_rate*loan_balance;
- 34 total_interest = total_interest + interest_for_this_month;
- 35 left_over_payment = monthly_payment - interest_for_this_month;
- 36 loan_balance = loan_balance - left_over_payment;
- 37
- 38 printf("Month(%i) interest = %10.2lf, left_over_payment = %1 0.2lf, balance = %10.2lf\n", month, interest_for_this_month, left_over_paymen t, loan_balance);
- 40 }
- 41 printf("Total Interest = %10.2f,\t", total_interest);
- 42 printf("Final Balance = %7.2f\n", loan_balance);
- 43 return 0;
- 44 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement