1.
1 2 3 4 5 6 7 8 9 10 11 12 | #include <stdio.h> int main(void) { printf(" *\n"); printf(" *\n"); printf(" *\n"); printf(" *\n"); printf("* *\n"); printf(" * *\n"); printf(" *\n"); return 0; } |
2.
1 2 3 4 5 6 7 8 9 | #include <stdio.h> #define _USE_MATH_DEFINES #include <math.h> int main(void) { printf("%f\n", (4.0f/3.0f)*M_PI*pow(10,3)); return 0; } | cs |
3.
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include <stdio.h> #define _USE_MATH_DEFINES #include <math.h> int main(void) { int radius; printf("Hello, Enter yours: "); scanf("%d", &radius); printf("%f\n", (4.0f/3.0f)*M_PI*pow(radius,3)); return 0; } | cs |
4.
1 2 3 4 5 6 7 8 9 10 | #include <stdio.h> int main(void) { float dollar; printf("Enter and amount: "); scanf("%f", &dollar); printf("With tax added: $%.2f\n", dollar*21/20); //세금 붙은 가격출력 return 0; } | cs |
5.
1 2 3 4 5 6 7 8 9 | #include <stdio.h> int main(void) { int x; scanf("%d", &x); printf("%d\n", (3*x*x*x*x*x)+(2*x*x*x*x)-(5*x*x*x)-(1*x*x)+(7*x)-6); return 0; } |
6. Horner's Rule
1 2 3 4 5 6 7 8 9 | #include <stdio.h> int main(void) { int x; scanf("%d", &x); printf("%d\n", ((((3*x+2)*x-5)*x-1)*x+7)*x-6); return 0; } | cs |
7.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <stdio.h> int main(void) { int amt; int bill_20, bill_10, bill_5, bill_1; printf("Enter a dollar amount: "); scanf("%d", &amt); bill_20 = amt / 20; bill_10 = (amt % 20) / 10; bill_5 = (amt % 10) / 5; bill_1 = amt % 5; printf("$20 bills: %d\n", bill_20); printf("$10 bills: %d\n", bill_10); printf(" $5 bills: %d\n", bill_5); printf(" $1 bills: %d\n", bill_1); return 0; } | cs |
8.
※ 실수형의 Rounding 때문인지 값이 실제 책에 있는 정답과는 다르다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <stdio.h> int main(void) { double loan, rate, payment, mir; printf("Enter amount of loan: "); scanf("%lf", &loan); printf("Enter interest rate: "); scanf("%lf", &rate); printf("Enter monthly payment: "); scanf("%lf", &payment); mir = (rate / 100) / 12; printf("Balance remaining after first payment: $%.2lf\n", loan - payment + loan * mir); printf("Balance remaining after second payment: $%.2lf\n", loan - payment*2 + loan * mir*2); printf("Balance remaining after third payment: $%.2lf\n", loan - payment*3 + loan * mir*3); return 0; } | cs |
'개발' 카테고리의 다른 글
[JAVA]JAVA 시험 정리 (0) | 2018.04.25 |
---|---|
자바 default 지정자는 패키지 private이라고도 한다. (0) | 2018.04.11 |
C# 프로그래밍 첫걸음(1) (0) | 2018.03.31 |
읽고 말하기 수열(개미 수열) C# 구현 (0) | 2018.03.31 |
[파이썬] 바운스! 게임 (0) | 2017.10.09 |
C의 역사, C의 장단점 (0) | 2017.04.03 |
댓글