# Equable Shapes

A shape is equable if its area is equal to its perimeter. Given ordered coordinates of polygon find whether the shape is equable or not.

Examples:

```Input : X[] = {0, 5, 0}
Y[] = {0, 0, 12}
Output : Equable Shape

Input : X[] = {0, 4, 4, 0}
Y[] = {0, 0, 4, 4}
Output : Equable Shape

Input: X[] = {0, 6, 6, 0}
Y[] = {0, 0, 4, 4}
Output: Not Equable Shape
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

We can find area of polygon using shoelace formula which is described in Area of a polygon with given n ordered vertices. We can also find its perimeter simply by adding distances between adjacent points.

## C++

```// C++ program to find equable shape
#include <bits/stdc++.h>
using namespace std;

// To calculate area of polygon
double polygonArea(double X[], double Y[], int n)
{
double area = 0.0;

// Calculate value of area using shoelace
// formula
int j = n - 1;
for (int i = 0; i < n; i++) {
area += (X[j] + X[i]) * (Y[j] - Y[i]);
j = i; // j is previous vertex to i
}

return abs(area / 2.0);
}

// To calculate perimeter of polygon
double polygonPerimeter(double X[], double Y[],
int n)
{
double perimeter = 0.0;

// Calculate value of perimeter
int j = n - 1;
for (int i = 0; i < n; i++) {
perimeter += sqrt((X[j] - X[i]) * (X[j] - X[i]) +
(Y[j] - Y[i]) * (Y[j] - Y[i]));
j = i; // j is previous vertex to i
}

return perimeter;
}

// To find equable shape
void equableShape(double X[], double Y[], int n)
{
// Find area and perimeter of polygon if
// they are equal then it is equable shape
if (polygonPerimeter(X, Y, n) == polygonArea(X, Y, n))
cout << "Equable Shape";
else
cout << "Not Equable Shape";
}

// Driver program to test above function
int main()
{
double X[] = { 0, 5, 0 };
double Y[] = { 0, 0, 12 };

int n = sizeof(X) / sizeof(X[0]);

equableShape(X, Y, n);

return 0;
}
```

## Java

```// Java program to find equable shape
class equable {

// To calculate area of polygon
static double polygonArea(double X[], double Y[], int n)
{
double area = 0.0;

// Calculate value of area using shoelace formula
int j = n - 1;
for (int i = 0; i < n; i++) {
area += (X[j] + X[i]) * (Y[j] - Y[i]);
j = i; // j is previous vertex to i
}

return Math.abs(area / 2.0);
}

// To calculate perimeter of polygon
static double polygonPerimeter(double X[], double Y[], int n)
{
double perimeter = 0.0;

// Calculate value of perimeter
int j = n - 1;
for (int i = 0; i < n; i++) {
perimeter += Math.sqrt((X[j] - X[i]) * (X[j] - X[i]) +
(Y[j] - Y[i]) * (Y[j] - Y[i]));
j = i; // j is previous vertex to i
}

return perimeter;
}

// To find equable shape
static void equableShape(double X[], double Y[], int n)
{
// Find area and perimeter of polygon if
// they are equal then it is equable shape
if (polygonPerimeter(X, Y, n) == polygonArea(X, Y, n))
System.out.println("Equable Shape");
else
System.out.println("Not Equable Shape");
}

// Driver program to test above function
public static void main(String[] args)
{
double X[] = { 0, 5, 0 };
double Y[] = { 0, 0, 12 };

int n = X.length;

equableShape(X, Y, n);
}
}
```

Output:

```Equable Shape
```

This article is contributed by nuclode. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

# GATE CS Corner    Company Wise Coding Practice

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.
0 Average Difficulty : 0/5.0