반응형

C_C++ 326

(C언어) 이차방정식의 해: 실근 중근 허근

이차방정식(quadratic equation) ax2+bx+c=0(a, b, c는 상수 a ≠ 0)의 형태로 표시되는 방정식. 이 방정식을 만족시키는 x의 값을 이 방정식의 근(根) 또는 해(解)라고 합니다. 다음은 이차방적식의 해를 구하는 C언어 프로그램입니다. 실근이 존재하는지의 판단은 다음과 같이 할 수 있습니다. 실근이 존재하는지 판단하기 b * b - 4 * a * c > 0 #define _CRT_SECURE_NO_WARNINGS #include #include int main() { double a, b, c, discriminant, root1, root2; printf("이차방정식 ax^2 + bx + c = 0\n"); printf("a, b, c 입력: "); scanf("%lf %l..

C_C++ 2023.04.24

(C언어) 2차원 배열을 시계방향으로 90도 회전시키기

2차원 배열을 시계방으로 90도 회전하는 C언어 코드입니다. #include #define ROW 3 #define COL 3 void rotate(int arr[][COL]) { int temp[ROW][COL]; int i, j; // 원본 복사 for (i = 0; i < ROW; i++) { for (j = 0; j < COL; j++) { temp[i][j] = arr[i][j]; } } // 시계방향으로 90도 회전 for (i = 0; i < ROW; i++) { for (j = 0; j < COL; j++) { arr[i][j] = temp[ROW - j - 1][i]; } } } int main() { int arr[ROW][COL] = { {1, 2, 3}, {4, 5, 6}, {7, ..

C_C++ 2023.04.22

(C언어) 연결리스트: 맨 앞에 노드 추가하기 Linked List

연결리스트에서 맨앞에 노드를 추가하는 C언어 코드입니다. 맨 뒤에 노드를 추가하는 코드도 있습니다. 이 블로그에서 [연결리스트]로 검색해 보세요. #include #include typedef struct Node { int data; struct Node* next; } Node; void insert(struct Node** headRef, int data) { struct Node* newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->data = data; newNode->next = *headRef; *headRef = newNode; } void print(struct Node* head) { struct Node* ptr = head;..

C_C++ 2023.04.12

(C언어) 연결리스트: 맨 뒤에 노드 추가하기 Linked List

연결리스트에서 맨뒤에 노드를 추가하는 C언어 코드입니다. #include #include typedef struct Node { int data; struct Node* next; } Node; // Node* head = NULL; void append(struct Node** head, int data) { struct Node* newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->data = data; newNode->next = NULL; if (*head == NULL) { *head = newNode; return; } struct Node* last = *head; while (last->next != NULL) { last = la..

C_C++ 2023.04.11

(C언어) uniq: 중복 라인을 제거하는 소스

파일 내용에서 똑 같은 행이 2개 이상 연달아 있으면 중복된 라인을 제거해서 한 개씩만 표준 출력하는 C언어 프로그램입니다. 테스트로 사용한 uniq.txt 파일은 다음과 같습니다. Get Get a string from a stream. a stream. a stream. Get a string from a stream. 실행된 결과는 다음과 같습니다. C언어 코드 #define _CRT_SECURE_NO_WARNINGS // Visual Studio #include #include #define TRUE1 #define FALSE0 #define LEN200 #define swap(a,b){ char *temp; temp=a; a=b; b=temp; } int main() { char buffer1[..

C_C++ 2023.03.28

비주얼스튜디오에서 스택(stack) 크기 설정(늘리기)

비주얼스튜디오에서 스택(stack) 크기는 기본으로 1MB로 설정되어 있습니다. 스택 크기는 프로젝트마다 설정할 수 있으므로 다음과 같이 크기를 설정할 수 있습니다. 1. [프로젝트] 메뉴[서 "속성" 속성을 선택합니다. 2. [링커] -> "시스템"에서 "스택 예약 크기" 입력합니다. 단위가 바이트(byte)이기 때문에 2M로 설정하고 싶다면 2097152를 입력하면 됩니다. 1 MB - 1048576 2 MB - 2097152 4 MY - 4194304 [

C_C++ 2023.03.25

(C언어) 복소수의 사칙연산: 합, 차(빼기), 곱(곱하기), 나누기

복소수의 사칙연산 [참고] 복소수의 사칙연산의 계산하는 방법은 다음 사이트를 참고했습니다. https://www.mathfactory.net/11177 C언어를 이용해서 복소수의 합을 구하는 코드만 작성해 보겠습니다. 복소수 정의는 구조체(struct)를 이용해서 정의합니다. #define _CRT_SECURE_NO_WARNINGS // Visual Studio #include struct complex { double real; double img; }; void add_complex(struct complex a, struct complex b) { struct complex c; c.real = a.real + b.real; c.img = a.img + b.img; printf("복소수의 합: %g..

C_C++ 2023.03.21
반응형