75.2k views
4 votes
Please write a complete program to calculate monthly payment given

The following formula

Monthly Pay=[ rate + rate /([1+rate]^months -1)] X principle

Where rate of %6 means 6/1200

And

Months means number of years x 12

Make the program user friendly. You may write method and call a method to

Do the job.

Possible data to test:

Principle 12200

Rate 7

Term in years 5

Monthly payment is: 241.57

Total Payment is: 14494.48

Interest Expense is 2294.48



only using c language...........not c++ plz

User Saori
by
4.7k points

1 Answer

5 votes

Step-by-step explanation:

Code with comments:

#include <stdio.h>

#include <math.h>

/* math library is required to use pow() function

First we need to create a function to calculate the Monthly Payment

It would take three inputs Rate, Years, and Principle amount

Then we converted the Rate and Months according to problem statement

pow() function is used to find (1+R)^M

Then finaly this function returns the value of Monthly Payment */

float MonthlyPay(float R, int M, int P)

{

R=R/1200;

M=M*12;

float po=pow((1+R),M);

float PayM=(R+(R/(po-1)))*P;

return PayM;

}

/* In the main() function we get 3 inputs from the user Years, Rate and Principle amount

then we call the MonthlyPay function and pass it 3 inputs that we got from the user

then we calculated the total Payment by multiplying the Monthly Pay and total number of months

then we calculated the interest Amount by subtracting the Principle Amount from total Pay

Testing is performed and output result is given at the end and also attached in the image */

int main(void)

{

float Rate;

int Year, Amount;

printf("Enter Years: ");

scanf("%d",&Year);

printf("Enter Rate: ");

scanf("%f",&Rate);

printf("Enter Principle Amount: ");

scanf("%d",&Amount);

float Pay = MonthlyPay(Rate, Year, Amount);

printf ("Monthly Payment is: %f \\", Pay);

float totalPay=Pay*Year*12;

printf ("Total Payment is: %f \\", totalPay);

float interest=totalPay-Amount;

printf ("Interest Expense is: %f \\", interest);

return 0;

}

Output:

Enter Years: 5

Enter Rate: 7

Enter Principle Amount: 12200

Monthly Payment is: 241.572767

Total Payment is: 14494.367188

Interest Expense is: 2294.367188

Please write a complete program to calculate monthly payment given The following formula-example-1
User Topanga
by
5.4k points