Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Turtle-hwan/chapter02/chapter02_자료형.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Turtle-hwan/chapter02/variables
Binary file not shown.
23 changes: 23 additions & 0 deletions Turtle-hwan/chapter02/variables.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdio.h>

void main() {
int example = 78;
// 서로 다른 자료형의 변수 3개 이상 선언 및 초기화

char example_char = 'A'; //문자형 변수 1byte / %c로 출력 / 정수로 출력하려면 %hhd

float example_float = 2.71828182846; //4byle 단일 정밀도

double example_double = 2.71828182846; //8byte 두배정밀도 실수 표현 / scanf 시는 double 형은 %lf로 받아야 함.



printf("%d\n", example);
// 앞서 선언한 모든 변수를 한 줄에 하나씩 출력
printf("문자 출력 : %c | 정수 출력 : %hhd\n", example_char, example_char);

printf("float 표현 %%1.16f 출력: %1.16f | %%f 출력: %f\n", example_float, example_float);
//float 형식은 double 보다 부정확
printf("double 표현 %%1.16f 출력: %1.16f | %%f 출력: %f\n", example_double, example_double);
//%f로 출력하면 float이 정확하게 표시할 수 있는 한계만큼 (소수점 아래 6자리 정도) 표현?!
}
Binary file added Turtle-hwan/chapter03/chapter03_연산자.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Turtle-hwan/chapter03/operator
Binary file not shown.
88 changes: 88 additions & 0 deletions Turtle-hwan/chapter03/operator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include <stdio.h>


void printBin_dec(int dec) { //십진수를 이진수로 바꾸어 출력
int d;
if (dec >= 0) {
d = dec;
}
else {
d = -dec;
}
int bin[32] = {0,};
int idx = 31;
while (d >= 2 && idx != 0) {
bin[idx] = d % 2;
idx--;
d = d / 2;
}
bin[idx] = 1;

if (dec < 0) { //2진법 음수 처리 -> 2의 보수 표현 // 2의 보수 : 1의 보수 + 1
for (int i = 31; i >= 0; i--) { //1의 보수
if (bin[i] == 1) {
bin[i] = 0;
}
else {
bin[i] = 1;
}
}
if (bin[31] == 1) { // + 1 처리
for (int i = 31; i >= 0; i--) {
if (bin[i] == 1) {
bin[i] = 0;
continue;
}
else {
bin[i] = 1;
break;
}
}
}
else {
bin[31] = 1;
}
}


//출력 부분 4자리씩 끊어서
printf("%d를 이진수로 바꾼 결과입니다.\n", dec);
for (int i = 0; i < 32; i++) {
printf("%d", bin[i]);
if (i % 4 == 3) {
printf(" ");
}
}
printf("\n");
}

void main() {
//int dec = 0b101111;
int dec1, dec2;

printf("연산할 첫 번째 십진수 입력 : ");
scanf("%d", &dec1);
printf("연산할 두 번째 십진수 입력 : ");
scanf("%d", &dec2);

printBin_dec(dec1);
printBin_dec(dec2);

printf("\n[비트 연산]\n");
printf("\n%d & %d = %d\n", dec1, dec2, dec1 & dec2);
printBin_dec(dec1 & dec2);

printf("\n%d | %d = %d\n", dec1, dec2, dec1 | dec2);
printBin_dec(dec1 | dec2);

printf("\n%d ^ %d = %d\n", dec1, dec2, dec1 ^ dec2);
printBin_dec(dec1 ^ dec2);

printf("\n~%d = %d\n", dec1, ~dec1);
printBin_dec(~dec1);

printf("\n%d << 3 = %d\n", dec1, dec1 << 3);
printBin_dec(dec1 << 3);

printf("\nsize of int : %ld byte\n", sizeof(dec1));
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Turtle-hwan/chapter04/printGrade_switch
Binary file not shown.
38 changes: 38 additions & 0 deletions Turtle-hwan/chapter04/printGrade_switch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdio.h>

void main() {
int score;
printf("점수 입력 : ");
scanf("%d", &score);

switch ((score*2)/10) {
case 20:
case 19:
printf("%d는 A+ 입니다.\n", score);
break;
case 18:
printf("%d는 A 입니다.\n", score);
break;
case 17:
printf("%d는 B+ 입니다.\n", score);
break;
case 16:
printf("%d는 B 입니다.\n", score);
break;
case 15:
printf("%d는 C+ 입니다.\n", score);
break;
case 14:
printf("%d는 C 입니다.\n", score);
break;
case 13:
printf("%d는 D+ 입니다.\n", score);
break;
case 12:
printf("%d는 D 입니다.\n", score);
break;
default:
printf("%d는 F 입니다.\n", score);
break;
}
}