n vertices make up the area of a polygon

Source: Internet
Author: User

Input

The input data contains multiple test instances, one row per test instance, and the beginning of each line is an integer n (3<=n<=100), which represents the number of sides of the polygon (and, of course, the number of vertices), followed by the coordinates of the n vertices given in a counterclockwise order (x1, y1, x2, y2 ... xn, Yn), in order to simplify the problem, all coordinates here are represented by integers.
All integers in the input data are within a 32-bit integer range, and n=0 represents the end of the data and does not handle it.

Output

For each test instance, output the corresponding polygon area, and the result is exactly one decimal point after the decimal.
The output for each instance takes up one row.

Sample Input
3 0 0 1 0 0 14 1 0 0 1-1 0 0-10

Sample Output
0.52.0

/*
The triangular three-vertex coordinates are a (a, b), C,d, C (e,f), then the area of the triangle is
s=1/2* third-order determinant,
The third-order determinant is:
A B 1
C D 1
E F 1
A*d+b*e+c*f-d*e-b*c-a*f
*/


#include <stdio.h>DoubleAreaDoubleADoubleBDoubleCDoubleDDoubleEDoublef);voidMain () {intN; Doublex[ -],y[ -]; while(SCANF ("%d", &n) = =1&& n>=3&& n<= -) { inti; Doublesum=0; for(i=0; i<n;i++) {scanf ("%LF%LF", x+i,y+i); if(i>=2) Sum+=area (x[0],y[0],x[i-1],y[i-1],x[i],y[i]); } printf ("%.1lf\n", sum/2); }}DoubleAreaDoubleADoubleBDoubleCDoubleDDoubleEDoublef) { returna*d+b*e+c*f-d*e-b*c-a*F;}

n vertices make up the area of a polygon

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.