Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Area of a triangle using templete
/* A(X1,Y1),B(X2,Y2),C(X3,Y3) represents the three point of a triangle respectively.We have to calculate the area of this triangle. */ #include<iostream> #include<cmath> using namespace std; template<typename A> float distance(A x1,A y1,A x2,A y2) // calculate the distance of any two points. { float cc=(pow(x1-x2,2)+pow(y1-y2,2)); return sqrt(cc); } double area(double a,double b,double c) // calculate the area of the triangle { double s=(a+b+c)/2; return sqrt(s*(s-a)*(s-b)*(s-c)); } int main() { int x1,y1,x2,y2,x3,y3; double a,b,c; cin>>x1>>y1>>x2>>y2>>x3>>y3; cout<<endl; a= distance(x1,y1,x2,y2); // a denotes the 1st side of the triangle b= distance(x2,y2,x3,y3); // b denotes the 1st side of the triangle c= distance(x3,y3,x1,y1); // c denotes the 1st side of the triangle cout<<a<<endl<<b<<endl<<c<<endl; cout<<area(a,b,c)<<endl; return 0; }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Float
Right view of a tree
scemo dd
Policy based smart pointer
1
template
ammmma
cache 内存消耗
CPP - ex 5 - solution
co_assign_1_ques_1
Please log in to post a comment.