Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- double calcMP(double pr, double iy, int ny, double nm);
- void prInfo(double pr, double iy, int ny, double mp, double nm);
- int main()
- {
- double pr= 0;
- double iy=0;
- int ny=0;
- double mp=0;
- double nm=0;
- printf("enter the total loan \n");
- scanf("%lf", &pr);
- printf("enter the interest rate/year(%) \n");
- scanf("%lf", &iy);
- printf("enter the amount of years \n");
- scanf("%d", &ny);
- double result = calcMP(pr, iy, ny, nm);//function call
- printf("the value of mp is %lf\n", result);
- double total = result*nm;
- prInfo(pr, iy, ny, result, nm);
- printf("the total paid is %.2f",total);
- return 0;
- }
- double calcMP(double pr, double iy, int ny,double nm)
- {
- double im=0;
- double mp = 0.0;
- nm = ny * 12;
- im= (iy/12)/100;
- mp = (pr*pow(1+im,nm)*im)/(pow(1+im,nm)-1);
- return mp;
- }
- void prInfo(double pr, double iy, int ny, double result, double nm)
- {
- nm = ny * 12;
- double ip=0;
- double im =(iy/12)/100;
- double prpaid=0;
- double nb=0;
- printf("Month\tOld\tMonthly\tInterest\tPrincipal\tNew\n");
- printf("\tBalance\tPayment\tPaid\t\tPaid\t\tBalance\n");
- for(int i = 1; i <= nm; i++)
- {
- ip = pr * im;
- prpaid = result - ip;
- nb = pr - prpaid;
- printf("%d\t%.2f\t%.2f\t%.2f\t\t%.2f\t\t%.2f\n", i, pr, result, ip, prpaid, nb);
- pr = nb;
- }
- }
Add Comment
Please, Sign In to add comment