Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
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
Tags
more
Archives
Today
Total
관리 메뉴

문타쿠, 공부하다.

[C언어 코딩 도장] Unit 48. 연습문제 및 심사문제 본문

C언어/C언어 코딩 도장

[C언어 코딩 도장] Unit 48. 연습문제 및 심사문제

개발새발 문타쿠 2023. 10. 29. 02:43

48.5 연습문제: 좌표 구조체 정의하기

#include <stdio.h>

struct Point2D
{
    int x; 
    int y;
};

int main(void)
{
    struct Point2D p1;

    p1.x = 10;
    p1.y = 20;

    printf("%d %d\n", p1.x, p1.y);

    return 0;
}

48.6 연습문제: typedef로 좌표 구조체 정의하기

#include <stdio.h>

typedef struct _Point2D
{
    int x; 
    int y;
} Point2D;

int main(void)
{
    Point2D p1;

    p1.x = 10;
    p1.y = 20;

    printf("%d %d\n", p1.x, p1.y);

    return 0;
}

48.7 연습문제: 익명 구조체로 좌표 구조체 정의하기

#include <stdio.h>

typedef struct
{
    int x; 
    int y;
} Point2D;

int main(void)
{
    Point2D p1;

    p1.x = 10;
    p1.y = 20;

    printf("%d %d\n", p1.x, p1.y);

    return 0;
}

48.8 심사문제: 자동차 계기판 구조체 선언하기

#include <stdio.h>

struct Dashboard
{
    int speed;
    char fuel;
    float mileage;
    int engineTemp;
    int rpm;

};

int main(void)
{
    struct Dashboard car1 = { 80, 'F', 5821.442871f, 200, 1830 };

    printf("Speed: %dkm/h\n", car1.speed);
    printf("Fuel: %c\n", car1.fuel);
    printf("Mileage: %fkm\n", car1.mileage);
    printf("Engine temp: %d°C\n", car1.engineTemp);
    printf("RPM: %d\n", car1.rpm);

    return 0;
}


48.9 심사문제: 자동차 계기판 구조체 정의하기

#include <stdio.h>

typedef struct _Dashboard
{
    int speed;
    char fuel;
    float mileage;
    int engineTemp;
    int rpm;

} Dashboard;

int main(void)
{
    Dashboard car1;

    car1.speed = 80;
    car1.fuel = 'F';
    car1.mileage = 5821.442871f;
    car1.engineTemp = 200;
    car1.rpm = 1830;

    printf("Speed: %dkm/h\n", car1.speed);
    printf("Fuel: %c\n", car1.fuel);
    printf("Mileage: %fkm\n", car1.mileage);
    printf("Engine temp: %d°C\n", car1.engineTemp);
    printf("RPM: %d\n", car1.rpm);

    return 0;
}