⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 struct.c

📁 里面包含很多c语言的源码
💻 C
字号:
/* Demonstrates structures that contain other structures. */

/* Receives input for corner coordinates of a rectangle and
   calculates the area. Assumes that the y coordinate of the
   lower-right corner is greater than the y coordinate of the
   upper-left corner, that the x coordinate of the lower-
   right corner is greater than the x coordinate of the upper-
   left corner, and that all coordinates are positive. */

#include <stdio.h>

int length, width;
long area;

struct coord{
    int x;
    int y;
};

struct rectangle{
    struct coord topleft;
    struct coord bottomrt;
} mybox;

int main( void )
{
    /* Input the coordinates */

    printf("\nEnter the top left x coordinate: ");
    scanf("%d", &mybox.topleft.x);

    printf("\nEnter the top left y coordinate: ");
    scanf("%d", &mybox.topleft.y);

    printf("\nEnter the bottom right x coordinate: ");
    scanf("%d", &mybox.bottomrt.x);

    printf("\nEnter the bottom right y coordinate: ");
    scanf("%d", &mybox.bottomrt.y);

    /* Calculate the length and width */

    width = mybox.bottomrt.x - mybox.topleft.x;
    length = mybox.bottomrt.y - mybox.topleft.y;

    /* Calculate and display the area */

    area = width * length;
    printf("\nThe area is %ld units.\n", area);

    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -