CENTROID | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

CENTROID

PROBLEM u r given a coordinates of a triangle's corners, (X1Y1),(X2Y2), and (X3Y3). Find the coordinates of the centroid of thr triangle (XC,YC),given that XC=(X1+X2+X3)/3 and YC=(Y1+Y2+Y3)/3. INPUT FORMAT: X1 Y1 X2 Y2 X3 Y3 OUTPUT FORMAT: XC YC SAMPLE INPUT: 0 0 1 1 2 5 SAMPLE OUTPUT: 1 2

23rd Sep 2016, 8:17 AM
Capr_Ver
Capr_Ver - avatar
2 Answers
+ 2
#include <iostream> using namespace std; int main(){ double x1, x2, x3, y1, y2, y3, CX, CY; cin>>x1>>y1>>x2>>y2>>x3>>y3; CX = (x1 + x2 + x3)/3; CY = (y1 + y2 + y3)/3; cout<<"CX = "<<CX<<endl; cout<<"CY = "<<CY<<endl; return 0; }
26th Sep 2016, 12:42 AM
Andres Mar
+ 1
thanks..
26th Sep 2016, 7:48 AM
Capr_Ver
Capr_Ver - avatar