전체 글
-
C언어 코딩도장 : 51.7 패킷 크기 조절하기개인 공부/C언어 공부 2020. 8. 21. 23:22
문제 : 다음 소스 코드를 완성하여 3이 출력되게 만드세요. 구조체 멤버의 이름은 마음대로 지어도 됩니다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include struct Packet { char a; char b; char c; }; int main() { struct Packet pkt; printf("%d\n", sizeof(pkt)); return 0; } Colored by Color Scripter cs 구조체 정렬 크기를 조절하지 않는 경우 - char형 변수 3개 선언 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include #pragma pack(push, 1) struct Packet { char a; short b; ..
-
C언어 코딩도장 : 51.6 암호화 헤더 크기 구하기개인 공부/C언어 공부 2020. 8. 21. 23:17
문제 : 다음 소스 코드를 완성하여 12가 출력되게 만드세요. 구조체 멤버의 이름은 마음대로 지어도 됩니다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include struct EncryptionHeader { char flags; int a; int b; }; int main() { struct EncryptionHeader header; printf("%d\n", sizeof(header)); return 0; } Colored by Color Scripter cs int형 이외에도 다양한 자료형을 활용할 수도 있다.
-
C언어 코딩도장 50.3 : 두 점 사이의 거리 구하기개인 공부/C언어 공부 2020. 8. 21. 18:16
문제 : 표준 입력으로 정수 4개가 입력되어 Point2D 구조체에 저장됩니다. 다음 소스 코드를 완성하여 두 점 사이의 거리가 출력되게 만드세요. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #define _CRT_SECURE_NO_WARNINGS #include #include struct Point2D { int x; int y; }; int main() { struct Point2D p1; struct Point2D p2; double distance; scanf("%d %d %d %d", &p1.x, &p1.y, &p2.x, &p2.y); int x = p1.x - p2.x; int y = p1.y - p2.y; dista..
-
C언어 코딩도장 49.9 구조체 포인터에 구조체 변수의 주소 할당하기카테고리 없음 2020. 8. 21. 18:07
문제 : 3차원 좌표 구조체 Point3D가 정의되어 있습니다. 다음 소스 코드를 완성하여 좌표 정보가 출력되게 만드세요. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include struct Point3D { float x; float y; float z; }; int main() { struct Point3D p1 = { 10.0f, 20.0f, 30.0f }; struct Point3D *ptr; ptr = &p1; printf("%f %f %f\n", ptr->x, ptr->y, ptr->z); return 0; } Colored by Color Scripter cs
-
C언어 코딩도장 49.8 사람과 자동차 구조체 포인터에 메모리 할당하기개인 공부/C언어 공부 2020. 8. 21. 17:39
문제 : 사람과 자동차 구조체가 정의되어 있습니다. 다음 소스 코드를 완성하여 사람과 자동차 정보가 출력되게 만드세요. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 #define _CRT_SECURE_NO_WARNINGS #include #include #include struct Person { char name[20]; int age; char address[100]; }; typedef struct { char name[20]; int number; int displacement; } Car; int main() { struc..
-
C언어 코딩도장 48.9 자동차 계기판 구조체 정의하기개인 공부/C언어 공부 2020. 8. 20. 07:56
문제 : 다음 소스 코드에서 자동차의 속도, 연료, 주행거리, 엔진 온도, 회전수를 표현하는 계기판 구조체를 정의하고, 계기판 정보가 출력되게 만드세요. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 #include typedef struct Dashboard { int speed; char fuel; float mileage; int engineTemp; int rpm; } Dashboard; int main() { Dashboard d1; d1.speed = 80; d1.fuel = 'F'; d1.mileage = 5821.442871f; d1.engineTemp = 200; d1.rpm = 1830; printf..
-
C언어 코딩도장 48.8 자동차 계기판 구조체 선언하기개인 공부/C언어 공부 2020. 8. 20. 07:53
문제 : 자동차에서 속도, 연료, 주행거리, 엔진 온도, 회전수를 표현하는 계기판 구조체가 정의되어 있습니다. 다음 소스 코드를 완성하여 계기판 정보가 출력되게 만드세요. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 #include struct Dashboard { int speed; char fuel; float mileage; int engineTemp; int rpm; }; int main() { struct Dashboard d1; d1.speed = 80; d1.fuel = 'F'; d1.mileage = 5821.442871; d1.engineTemp = 200; d1.rpm = 1830; printf("..
-
6주차 미션 - 1개인 공부/코딩뉴비 챌린지 2020. 8. 19. 07:01
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465#include #include typedef struct stack{ int top; int capacity; int* array;} Stack; Stack* createStack(int capacity) { Stack* stack = (Stack*)malloc(sizeof(Stack)); stack->capacity = capacity; stack->top = -1; stack->array = (int *)malloc(stack->capacity*sizeof(int)); return st..