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);
- void prInfo(double pr, double iy, int ny, double mp);
- int main()
- {
- double pr;
- double iy;
- int ny;
- double mp;
- 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);//function call
- printf("the value of mp is %lf\n", result);
- prInfo(pr, iy, ny, result);
- printf("the total paid is %.2f", result * nm);
- return 0;
- }
- double calcMP(double pr, double iy, int ny)
- {
- double nm;
- double im;
- 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 = ny*12;
- double ip;
- double im =(iy/12)/100;
- double prpaid;
- double nb;
- printf("Month Old Monthly Interest Principal New\n");
- printf(" Balance Payment Paid Paid Balance\n");
- for(int i = 1; i <= nm; i++)
- {
- ip = pr * im;
- prpaid = result - ip;
- nb = pr - prpaid;
- printf("%d %.2f %.2f %.2f %.2f %.2f\n", i, pr, result, ip, prpaid, nb);
- pr = nb;
- }
- }
Add Comment
Please, Sign In to add comment