Cod sursa(job #2547678)

Utilizator AlexNicuNicu Alexandru AlexNicu Data 15 februarie 2020 16:12:55
Problema Aria Scor 100
Compilator c-64 Status done
Runda Arhiva educationala Marime 0.66 kb
#include <stdio.h>
#include <stdlib.h>

long double abs1( long double a ) {
    if ( a < 0 )
       return -a;
    return a;
}

int main() {
    FILE *fin, *fout;
    fin = fopen ( "aria.in", "r" );
    fout = fopen ( "aria.out", "w" );
    int n, i;
    long double x1, y1, x2, y2, x3, y3;
    long double ans;
    fscanf ( fin, "%d%Lf%Lf", &n, &x1, &y1 );
    x3 = x1;
    y3 = y1;
    ans = 0;
    for ( i = 1; i <= n - 1; i++ ) {
        fscanf ( fin, "%Lf%Lf", &x2, &y2 );
        ans = ans + ( x2 - x1 ) * ( y1 + y2 );
        x1 = x2;
        y1 = y2;
    }
    ans += ( x3 - x2 ) * ( y3 + y2 );
    ans /= 2;
    fprintf( fout, "%.5Lf", abs1(ans) );
    return 0;
}