C + + Informatics Olympiad A one-pass question bank 1034 compute the Triangle area __c++

Source: Internet
Author: User
Calculate the area of a triangle


Time limit: 1000 ms Memory limit: 65536 KB
Number of submissions: 1813 Pass: 622


"topic description"
There is a triangle on the plane, its three vertex coordinates (x1, y1), (x2, y2), (x3, y3), then what is the area of the triangle, accurate to two decimal places.


Enter
Enter only one line, including 6 single-precision floating-point numbers, corresponding to x1, y1, x2, y2, X3, Y3, respectively.


Output
The output is also one line, the area of the output triangle, accurate to two digits after the decimal point.


"Input Sample"
0 0 4 0 0 3
"Output Sample"
6.00
Source


No
Source:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace Std;
int main ()
{
Double x1,x2,x3,y1,y2,y3,p,s,a,b,c;
Cout.precision (2);
cin>>x1>>y1>>x2>>y2>>x3>>y3;
A=sqrt ((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));
B=sqrt ((x3-x2) * (X3-X2) + (y3-y2) * (Y3-y2));
C=sqrt ((x3-x1) * (x3-x1) + (y3-y1) * (y3-y1));
p= (A+B+C)/2;
S=sqrt (p* (p-a) * (p-b) * (p-c));
cout<<fixed<<s;
return 0;
}

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.