[ create a new paste ] login | about

Link: http://codepad.org/lFa5vpsL    [ raw code | output | fork ]

C++, pasted on Oct 4:
#include <cmath>
#include <iostream>
using namespace std;

struct point
{
    float x;
    float y;
    float length(point pt){
        return sqrt(pow(pt.x - x, 2.0f) + pow(pt.y - y, 2.0f));
    }
};

int main(){
    point A = {1, 1};
    point B = {3, 2};
    point C = {5, 5};
    float p = (A.length(B) + A.length(C) + B.length(C)) / 2;
    float S =  sqrt(p*(p - A.length(B))*(p - A.length(C))*(p - B.length(C)));
    cout<<"p= "<<p<<endl;
    cout<<"S= "<<S<<endl;
    return 0;
}


Output:
1
2
p= 5.74924
S= 2


Create a new paste based on this one


Comments: