Pagini recente » Cod sursa (job #997027) | Cod sursa (job #493477) | Cod sursa (job #2980432) | Cod sursa (job #1962426) | Cod sursa (job #1798306)
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
FILE* fin = fopen("aria.in","r");
FILE* fout = fopen("aria.out", "w");
struct Point
{
double x, y;
};
double computeArea(Point p1, Point p2)
{
return p1.x*p2.y - p2.x*p1.y;
}
int main()
{
double area = 0.0;
int nrOfPoints;
Point current,previous,first;
fscanf(fin, "%d", &nrOfPoints);
fscanf(fin, "%lf %lf", &previous.x, &previous.y);
first = previous;
for (int i = 1; i < nrOfPoints; i++)
{
fscanf(fin, "%lf %lf", ¤t.x,¤t.y);
area += computeArea(previous, current);
previous = current;
}
area += computeArea(previous, first);
fprintf(fout,"%lf", area/2.0);
}