Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Area of a triangle using templete
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
/* 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; }
g++
2 5 6 8 9 3
Show compiler warnings
[
+
] Compiler args
[
-
]
Show input
Compilation time: 1.07 sec, absolute running time: 0.18 sec, cpu time: 0 sec, memory peak: 3 Mb, absolute service time: 1.32 sec
fork mode
|
history
|
discussion
5 5.83095 7.28011 14.5