Pagini recente » Cod sursa (job #2810771) | Cod sursa (job #2952377) | Cod sursa (job #242317) | Cod sursa (job #2819743) | Cod sursa (job #1484146)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double aria(double x1, double y1, double x2, double y2) {
double res = (x1 * y2 - x2 * y1);
return res;
}
int main() {
FILE* fin = fopen("aria.in", "r");
int n;
fscanf(fin, "%d\n", &n);
double* x = malloc((n + 1) * sizeof(double));
double* y = malloc((n + 1) * sizeof(double));
int i;
for(i=0; i<n; i++) {
fscanf(fin, "%lf %lf\n", &x[i], &y[i]);
}
fclose(fin);
x[n] = x[0];
y[n] = y[0];
double res = 0.0;
for(i=0; i<n; i++) {
res = res + x[i] * y[i + 1] - x[i + 1] * y[i];
}
res = res + aria(x[n - 1], y[n - 1], x[0], y[0]);
res = fabs(res / 2.0);
FILE* fout = fopen("aria.out", "w");
fprintf(fout, "%lf\n", res);
free(x);
free(y);
fclose(fout);
return 0;
}