Pagini recente » Cod sursa (job #1651902) | Cod sursa (job #2429296) | Cod sursa (job #143014) | Cod sursa (job #1289358) | Cod sursa (job #3317810)
#include <math.h>
#include <stdio.h>
typedef struct point2d {
long double x, y;
} p2d;
long double triangle_surface(p2d p1, p2d p2, p2d p3)
{
long double surface = p1.x * p2.y + p2.x * p3.y + p1.y * p3.x - p3.x * p2.y -
p1.x * p3.y - p2.x * p1.y;
return surface / 2;
}
int main(void)
{
freopen("aria.in", "r", stdin);
int n;
scanf("%d ", &n);
p2d p1, p2, p3;
long double surface = 0;
scanf("%Lf%Lf%Lf%Lf%Lf%Lf", &p1.x, &p1.y, &p2.x, &p2.y, &p3.x, &p3.y);
n -= 3;
surface += triangle_surface(p1, p2, p3);
while (n-- > 0) {
p2.x = p3.x;
p2.y = p3.y;
scanf("%Lf%Lf", &p3.x, &p3.y);
surface += triangle_surface(p1, p2, p3);
}
freopen("aria.out", "w", stdout);
printf("%Lf\n", surface);
return 0;
}