분류 전체보기 477

서울대 프로그래밍연습 2020 기출 문제 풀이 | print, 피보나치 수열, 스택, 등차수열

#include #include #define EMPTY 0 #define FULL 10000 struct elem { char data; struct elem *next; }; typedef struct elem elem; struct stack { int cnt; elem *top; }; typedef struct stack stack; void print(void); // 1전 int max_2(void); // 2번 void fib(char, char, int); // 3번 int stack_deal(void); // 4번 push pop void push_stk(int, stack*); void print_stk(stack*); int main(void){ /* print(); */ /* pri..

Computer Science/C 2021.12.18

C언어 11강 | File I/O | 끝 부분 아직 하는 중

file I/O 이번 강의를 요약해보자. #include 에 있는 파일들을 이용하는데, FILE *variable_name이라는 file 포인터가 있다. 이 구조체는 파일의 상태에 대하여 서술하는 것임 fopen(), fprintf(), fscanf(), fputc(),fgetc(), fclose() 함수로 파일을 조작한다. fopen(), fclose() 함수부터 시작해보자. 기본적인 골격은 다음과 같다. step 1. 파일 포인터 선언 FILE *fp; step 2. 파일 오픈 fp = fopen("filename", "mode"); step 3. 어쩌구저쩌구 진행 step 4. 파일 닫기 fclose(fp); 이때 fopen의 mode에는 다양한 것이 있다. [1] text file용 fp = fo..

Computer Science/C 2021.12.17

C언어 8강 | 전처리기 Preprocessors

preprocessor #include #define이 대표적 use of #include #include #include #include "filename" : 직접 만든 것 (파일 경로 일치해야 함) use of #define #define identifier token_string #define SECONDS_PER_DAY (60*60*24) #define PI 3.141592 #define C 299792.458 #define EOF -1 #define MAXINT 2147483647 macros with arguments #define SQ(x) ((x)*(x)) #define SQ(x) x*x #define SQ(x) (x) * (x) 셋 다 다른 표현임 주의 #define min(x, y) ..

Computer Science/C 2021.12.17

C언어 7강 | Bitwise operators

중요한 부분 : enum, bit로 출력하기, Bitwise operation bitwise logical operator complement : ~ AND : & OR : | XOR : ^ // example #include int main() { unsigned char num1 = 1; //0000 0001 unsigned char num2 = 3; //0000 0011 printf("%d\n", num1&num2); // 0000 0001 printf("%d\n", num1|num2); // 0000 0011 printf("%d\n", num1^num2); // 0000 0010 return 0; } bitwise shift operator left shift : shift 연산자는 두번째 피연산..

Computer Science/C 2021.12.17

C언어 10강 | Structures and list processing | 제일 중요함 ***

매우 중요함 linear linked list stack queue binary tree structures and list processing self referential structures 자기 자신을 가리키는 포인터 변수를 멤버로 갖는 구조체 struct list { int data; struct list *next; }; struct list a, b, c; a.data = 1; b.data = 2; c.data = 3; a.next = &b; b.next = &c; c.next = NULL; printf("%d\n%d\n", a.next->data, a.next->next->data); linear linked lists 배열은 배열인데, struct가 일렬로 연결된 리스트(꼬리잡기) #inc..

Computer Science/C 2021.12.17

C언어 9강 | 구조체 Structures

Structures array 배열과 structure 구조체의 차이는? array는 동질적인 type의 데이터를 묶어서 보여주기 위해 사용하는 것이라면, structure는 여러 타입의 변수를 통합하여 보여주기 위해 사용한다. struct랑 typedef가 자주 묶여서 사용된다. 아래는 그 예시들 struct card{ int pips; char suit; }; typedef struct card card; card c1, c2; card c1, c2로 선언한 아이들의 pips, suit(멤버)에 접근하려면, c1.pips, c2.suit와같이 .을 이용하면 된다. 멤버의 네임은 달라야 한다. struct fruit { char *name; int calories; }; typedef struct fr..

Computer Science/C 2021.12.17

C언어 6강 | Arrays, Pointers, and Strings | 중요!

One dimensional arrays array 배열 선언하는 법 : type array_name[size]; array initialization 배열 초기화 array는 storage class가 auto, external, static일 수 있다(register는 안됨) auto인 경우에는 선언만 해주면, 쓰레기값이 들어있으므로꼭 초기화를 해주어야 한다. float f[5] = {0.0, 1.0, 2.0, 3.0, 4.0}; int a[100] = {0}; int a[] = {2,3,5,-7}; array subscripting 배열 첨자 a[i]로 배열 요소에 접근한다. sorting 배열을 이용하여, 4,-681,52,-23,15,9,13을 정렬하는 프로그램을 짜보자. 1) bubble so..

Computer Science/C 2021.12.16

C언어 5강 | 함수 Functions | call by value, extern, static 등

Functions 효과적인 문제 해결의 정수는 문제 분해다. 이를 위해 함수가 필요하다. (모듈화라고 함) Function Definition 함수는 함수 프로토타입, 함수 정의(헤더/바디), 함수 call(main)으로 구성된다. 이 중 함수 정의부터 살펴보자. 함수 정의의 골격은 다음과 같다. type function_name(parameter list) { declarations; statements; } 예시를 보자 #include #include long fact(int n) { int i; long product = 1; for (i=2;i=0&&m>=0); assert(n>=m); comb=fact(n)/(fact(m)*fact(n-m)); printf("%dC%d=%ld\n", n, m, ..

카테고리 없음 2021.12.16

C언어 4강 | Flow of Control | 반복문, 조건문, 순차 구조

제어 구조 Flow of control 프로그램은 보통 순차 제어 구조로 진행된다. sequential flow of control 그런데 어떤 경우에는 선택, 반복 구조를 차용해야 할 때가 있다. 선택 구조 : a choice of action if, if-else, switch 반복 구조 : repetition while, for, do Relational, Equality, Logical operators true인 경우 nonzero value false인 경우 zero value 리턴함 relational : = equality : == != logical operators : && || Relational operators and expressions = 등이 있다. 만약 (a < ..

Computer Science/C 2021.12.16

C언어 3강 | 데이터 타입 | char, int(short, long,unsigned), float, typedef

Declaration, Expression, Assignment Declarations 선언 변수 Variables와 상수 constants는 반드시 사용되기 전에 선언되어야 한다. 선언에서는 [1] 변수와 type을 연결짓고 [2] 컴파일러로 하여금 특정한 양의 메모리를 잡아두도록 한다. #include int main(void){ int a, b, c; float x, y = 3.3, z = -7.7; printf("Input two integers: "); scanf("%d%d", &b, &c); a = b+c; x = y+z; } Expressions 함수, 변수, 연산자, 상수 등을 조합하여 만들어진다. assignment statement variable = expression; 기본적인 데이..

Computer Science/C 2021.12.16