Pagini recente » Cod sursa (job #2526966) | Cod sursa (job #1187744) | Cod sursa (job #1059119)
#include <fstream>
#include <vector>
#include <iomanip>
#define dmax 100000
using namespace std;
ifstream fin("aria.in");
ofstream fout("aria.out");
struct point {
double x,y;
} v[dmax];
int n;
double s;
//functions declaration
void read();
//reads the input file
double area(point x1, point x2);
// calculates the area of the triangle formed by the two points x1 & x2 with the origin O(0,0)
int main() {
read();
for(int i=0;i<n-1;i++)
s=s+area(v[i],v[i+1]);
s=s+area(v[n-1],v[0]);
fout << setprecision(5) << s;
return 0;
}
void read() {
fin>>n;
for(int i=0; i<n; i++)
fin>>v[i].x>>v[i].y;
}
double area(point p1, point p2) {
return (p1.x*p2.y-p2.x*p1.y)/2;
}