当前位置:网站首页>Classic example of C language - loan balance

Classic example of C language - loan balance

2022-07-24 00:25:00 Blue_ lan18

Programming calculation first 、 second 、 The remaining loan amount after repayment in the third month :
 


# include <stdio.h>

int main()
{
	double amount;// The total loan amount 
	double rate;// Annual interest rate 
	double monthlyPayment;// Monthly repayment amount 
	double firstPayment = 0;// Loan balance in the first month 
	double secondPayment = 0;
	double thirdPayment = 0;
	double monthlyRate = 0.01 * 6.0/12;// An interest 

	printf("Enter amount of loan: ");
	scanf("%lf", &amount);
	printf("Enter rate of loan: ");
	scanf("%lf", &rate);
	printf("Enter monthlyPayment of loan: ");
	scanf("%lf", &monthlyPayment);
/* Keep two decimal places when displaying the balance after each repayment . Tips : The loan balance of each month minus the repayment amount ,
 You also need to add the product of the loan balance and the monthly interest rate . The monthly interest rate is calculated by converting the interest rate entered by the user into a percentage and dividing it by 12.
*/

	firstPayment = amount - monthlyPayment + amount * monthlyRate;
	secondPayment = firstPayment - monthlyPayment + firstPayment * monthlyRate;
	thirdPayment = secondPayment - monthlyPayment + secondPayment * monthlyRate;

	printf("Balance remaining after first payment: %.2f\n",firstPayment);
	printf("Balance remaining after second payment: %.2f\n", secondPayment);
	printf("Balance remaining after third payment: %.2f\n", thirdPayment);
}

 

原网站

版权声明
本文为[Blue_ lan18]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207231047358058.html