Cod sursa(job #1871786)

Utilizator bogobatBerbece Daniel bogobat Data 7 februarie 2017 17:35:49
Problema Aria Scor 70
Compilator c Status done
Runda Arhiva educationala Marime 0.71 kb
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    long n;
    double x1, x2, y1, y2, firstx, firsty;
    FILE * in = fopen("aria.in", "r");
    fscanf(in, "%ld", &n);
    fscanf(in, "%lf %lf", &x1, &y1);
    fscanf(in, "%lf %lf", &x2, &y2);
    n -= 2;
    firstx = x1;
    firsty = y1;
    double sum = 0;
    sum += (x1*y2 - x2*y1);
    x1 = x2;
    y1 = y2;
    while( n ){
        fscanf(in, "%lf %lf", &x2, &y2);
        sum += (x1*y2 - x2*y1);
        x1 = x2;
        y1 = y2;
        n--;
    }
    sum += (x1*firsty - firstx*y1);
    sum /= 2;
    fclose(in);
    FILE * out = fopen("aria.out", "w");
    fprintf(out, "%lf", sum);
    fclose(out);
    return 0;
}