----연습문제----
5번
3x^5 + 2x^4 - 5x^3 - x^2 + 7x - 6
를 표현할 때, C에는 지수 오퍼레이터가 없는 관계로 x^5를 나타내려면 x*x*x*x*x로 써야 한다.
따라서: 3 * x*x*x*x*x + 2 * x*x*x*x - 5 * x*x*x - x*x + 7 * x - 6라고 써야 한다.
((((3 * x + 2)*x - 5)*x - 1)*x + 7)*x - 6) 이렇게 쓸 수도 있다. (Horner's Rule)
7번 - int / int는 python의 a//b와 같다.
#pragma warning(disable:4996)
#include <stdio.h>
int main(void)
{
int dollar;
int bill_1, bill_5, bill_10, bill_20;
int rest;
printf("Enter a dollar amount: ");
scanf("%d", &dollar);
bill_20 = dollar / 20;
rest = dollar - 20 * bill_20;
bill_10 = rest / 10;
rest = rest - 10 * bill_10;
bill_5 = rest / 5;
bill_1 = rest - 5 * bill_5;
printf("$20 bills: %d \n$10 bills: %d \n $5 bills: %d \n $1 bills: %d\n", bill_20, bill_10, bill_5, bill_1);
}
8번
#pragma warning(disable:4996)
#include <stdio.h>
int main(void)
{
float amount, ir, monthly;
float total1, total2, total3;
printf("Enter amount of loan: ");
scanf("%f", &amount);
printf("Enter interest rate: ");
scanf("%f", &ir);
printf("Enter monthly paymetn: ");
scanf("%f", &monthly);
total1 = amount * (1 + ir / 1200) - monthly;
total2 = total1 * (1 + ir / 1200) - monthly;
total3 = total2 * (1 + ir / 1200) - monthly;
printf("Balance remaining after first payment: %.2f\n", total1);
printf("Balance remaining second first payment : %.2f\n", total2);
printf("Balance remaining third first payment : %.2f\n", total3);
}