using System.Collections.Generic;
using System.Threading.Tasks;
namespace PerimeterAndAreaOfPolygon
public Point(double X, double Y)
public double Distance(Point p2)
return Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2));
public Polygon(List<Point> polygon)
Console.WriteLine("Cannot make polygon with less than 3 points!");
public double Perimeter()
for (int i = 0; i < m-1; i++)
perimeter += p1.Distance(p2);
for (int i = 0; i < m-1; i++)
return Math.Abs(left-right)/2;
public static void Main()
Console.WriteLine(@"Program that calculates the perimeter and the area of given polygon (not necessarily convex)
consisting of n floating-point coordinates in the 2D plane.");
Console.WriteLine("Write n = ");
int n = int.Parse(Console.ReadLine());
List<Point> listOfPoints = new List<Point>{};
for (int i = 0; i < n; i++)
Console.WriteLine("Write coordinates of point {0}:", i + 1);
string line = Console.ReadLine();
string[] list = line.Split(' ');
double x = double.Parse(list[0]);
double y = double.Parse(list[1]);
Point p = new Point(x, y);
Polygon polygon = new Polygon(listOfPoints);
double perimeter = polygon.Perimeter();
double area = polygon.Area();
Console.WriteLine("The area is {0:0.00} and the perimeter is {1:0.00}.", area, perimeter);