Although the question is simple, I'll leave it as a snippet crib:
#include <algorithm> /* x1, y1 - левая нижняя точка первого прямоугольника x2, y2 - правая верхняя точка первого прямоугольника x3, y3 - левая нижняя точка второго прямоугольника x4, y4 - правая верхняя точка второго прямоугольника */ int f(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) { int left = std::max(x1, x3); int top = std::min(y2, y4); int right = std::min(x2, x4); int bottom = std::max(y1, y3); int width = right - left; int height = top - bottom; if ((width < 0) || (height < 0)) return 0; return width * height; }
Based on the text of the question, I believe that the coordinates grow from the lower left corner (if Y grows from top to bottom, amend the corresponding ones).
The idea is simple, illustrated in the picture (for the width, for the height is the same):

с.left = max(a.left, b.left);,с.top = max(a.top, b.top);,c.right = min(a.right, b.right );,c.bottom = min(a.bottom, b.bottom );(well, another check that the non-negative dimensions turned out, in case they do not overlap). - Vladimir Gamalyan