Function GetRectangleArea
The function/method getRectangleArea accepts two arguments points and point2 representing two opposite vertices of a CAM CSA rectangle. Any two sides of the rectangle are always parallel to X-ads
The function/method getRectangleArea must retum an integer representing the area of the given rectangle.
Your task is to implement the function getRectangleArea so that it passes all the test case CATTARE CAM
The following structure is used to represent Point and is already defined in the default code (Do not write these definition again in
your code).
typedef struct point
int X
int Y;
Point;
Proce
IMPORTANT: Do not write the main() function as it is already defined.
Example Input/Output 1:
Input
1
43
Output
6
Explanation:
The point (1, 1) indicates the bottom-left comer of the rectangle The point (4, 3) indicates the top-right comer of the rectangle
The breadth of the rectangle is 2.
So the area of the rectangle is 6 (3*2).
Example Input/Output 2:
Input:
2-3
-51
Output:
28
Explanation:
The point (2, -3) indicates the bottom-right corner of the rectangle.
The point (-5, 1) indicates the top-left corner of the rectangle
The length of the rectangle is 7
The breadth of the rectangle is 4
So the area of the rectangle is 28 (74)
SOLUTION :
#include <stdio.h>
#include <math.h>
typedef struct point
{
int X;
int Y;
} Point;
int getRectangleArea(Point *point1,Point *point2){
return abs(point1->X - point2->X) * abs(point1->Y - point2->Y);
}
int main()
{
Point P1, P2, P3;
scanf("%d %d\n", &P1.X, &P1.Y);
scanf("%d %d", &P2.X, &P2.Y);
printf("%d", getRectangleArea(&P1, &P2));
return 0;
}
********************************************************************************
Post a Comment