Pagini recente » Cod sursa (job #2488577) | Cod sursa (job #188642) | Cod sursa (job #81083) | Cod sursa (job #1917384) | Cod sursa (job #1484120)
#include <stdio.h>
#include <stdlib.h>
double aria(double x1, double y1, double x2, double y2) {
double res = 0.5 * (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 * sizeof(double));
double* y = malloc(n * sizeof(double));
int i;
for(i=0; i<n; i++) {
fscanf(fin, "%lf %lf\n", &x[i], &y[i]);
}
fclose(fin);
double res = 0.0;
for(i=0; i<n-1; i++) {
res = res + aria(x[i], y[i], x[i + 1], y[i + 1]);
}
res = res + aria(x[n - 1], y[n - 1], x[0], y[0]);
FILE* fout = fopen("aria.out", "w");
fprintf(fout, "%lf\n", res);
free(x);
free(y);
fclose(fout);
return 0;
}