Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
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 50. 연습문제 및 심사문제 본문

C언어/C언어 코딩 도장

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

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

50.2 연습문제: 사각형의 넓이 구하기

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

struct Rectangle
{
    int x1, y1;
    int x2, y2;
};

int main(void)
{
    struct Rectangle rect;
    int area;

    rect.x1 = 20;
    rect.y1 = 20;
    rect.x2 = 40;
    rect.y2 = 30;

    int width = abs(rect.x2 - rect.x1);
    int height = abs(rect.y2 - rect.y1);

    area = width * height;

    printf("%d\n", area);

    return 0;
}


50.3 심사문제: 두 점 사이의 거리 구하기

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>

struct Point2D
{
    int x;
    int y;
};

int main(void)
{
    struct Point2D p1;
    struct Point2D p2;
    double distance;

    scanf("%d %d %d %d", &p1.x, &p1.y, &p2.x, &p2.y);

    int a = abs(p2.x - p1.x);
    int b = abs(p2.y - p1.y);

    distance = sqrt(pow(a, 2) + pow(b, 2));

    printf("%f\n", distance);

    return 0;
}