Guest User

Untitled

a guest
Feb 21st, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. double calcMP(double pr, double iy, int ny);
  4. void prInfo(double pr, double iy, int ny, double mp);
  5. int main()
  6. {
  7. double pr;
  8. double iy;
  9. int ny;
  10. double mp;
  11. printf("enter the total loan \n");
  12. scanf("%lf", &pr);
  13. printf("enter the interest rate/year(%) \n");
  14. scanf("%lf", &iy);
  15. printf("enter the amount of years \n");
  16. scanf("%d", &ny);
  17.  
  18. double result = calcMP(pr, iy, ny);//function call
  19. printf("the value of mp is %lf\n", result);
  20. prInfo(pr, iy, ny, result);
  21. printf("the total paid is %.2f", result * nm);
  22. return 0;
  23. }
  24.  
  25. double calcMP(double pr, double iy, int ny)
  26. {
  27. double nm;
  28. double im;
  29. double mp = 0.0;
  30.  
  31.  
  32. nm = ny * 12;
  33.  
  34. im= (iy/12)/100;
  35.  
  36. mp = (pr*pow(1+im,nm)*im)/(pow(1+im,nm)-1);
  37.  
  38. return mp;
  39.  
  40.  
  41. }
  42. void prInfo(double pr, double iy, int ny, double result)
  43. {
  44. double nm = ny*12;
  45. double ip;
  46. double im =(iy/12)/100;
  47. double prpaid;
  48.  
  49.  
  50. double nb;
  51. printf("Month Old Monthly Interest Principal New\n");
  52. printf(" Balance Payment Paid Paid Balance\n");
  53. for(int i = 1; i <= nm; i++)
  54. {
  55. ip = pr * im;
  56. prpaid = result - ip;
  57. nb = pr - prpaid;
  58. printf("%d %.2f %.2f %.2f %.2f %.2f\n", i, pr, result, ip, prpaid, nb);
  59. pr = nb;
  60. }
  61. }
Add Comment
Please, Sign In to add comment