Write a C program named loanCalcc that calculates monthly pa
Solution
#include<stdio.h>
#include<math.h>
int main()
{
float r,l,intrest,mp,c,balance,principle;
int n,i;
//taking user input...
printf(\"Enter loan amount:\");
scanf(\"%f\",&l);
printf(\"Enter interest rate per year:\");
scanf(\"%f\",&r);
printf(\"Number of payments:\");
scanf(\"%d\",&n);
c=r/(100*12);
mp=l*c*(pow(1+c,n))/(pow(1+c,n)-1);
printf(\"monthly amount hould be %f\ \",mp);
printf(\"#\\tPaymen Principle intrest Balance\ \");
intrest=r*balance/1200;
balance=l+intrest;
for(i=1;i<=n;i++)//printing output
{
intrest=r*balance/1200;
principle=mp-intrest;
balance =balance-mp;//total amount
if(balance<0)
balance=0;
printf(\"%d\\t%f%\\t%f\\t%f\\t%f\ \",i,mp,principle,intrest,balance);
}
return 0;
}
Output:
Enter loan amount:500
Enter interest rate per year:7.5
Number of payments:5
monthly amount hould be 101.882408
# Paymen Principle intrest Balance
1 101.882408 98.757408 3.125000 398.117584
2 101.882408 99.394173 2.488235 296.235168
3 101.882408 100.030937 1.851470 194.352753
4 101.882408 100.667702 1.214705 92.470345
5 101.882408 101.304466 0.577940 0.000000
Process exited normally.
Press any key to continue . . .

