面试题答案
一键面试#include <stdio.h>
struct Point {
int x;
int y;
};
struct Rectangle {
struct Point topLeft;
struct Point bottomRight;
};
// 计算矩形面积的函数
int calculateArea(struct Rectangle *rect) {
int width = rect->bottomRight.x - rect->topLeft.x;
int height = rect->bottomRight.y - rect->topLeft.y;
return width * height;
}
int main() {
struct Rectangle rect = {
.topLeft = {1, 1},
.bottomRight = {5, 5}
};
int area = calculateArea(&rect);
printf("矩形的面积为: %d\n", area);
return 0;
}