+ 2

Write a function that takes coordinates of three points namely x1,y1,x2,y2,x3,y3 and to print whether the formed triangle is a).Equilateral b).scalen c.)Right angle Triangle.

1st Oct 2016, 4:00 AM
SAMBHAV KUMAR THAKUR
SAMBHAV KUMAR THAKUR - avatar
2 Respostas
+ 3
Alright, so first, we have to define the three triangles. (hope you realize a scalen triangle can be a right angle triangle) 1. equilateral triangle had same length on all three sides 2. scalen triangle has different length on all 3 sides. 3. with right angle triangle, a^2 + b^2 =c^2 (pythagorean theorem) must work. ^2 means squared. So let's do this. //program start #include <iostream> //for cout #include <cmath> //for pow and sqrt #include <algorithm> //for max using namespace std; double x1, y1, x2, y2, x3, y3; //variables are defined double s1, s2, s3; //side 1, side 2, and side 3 //set s1 as distance from point (x1, y1) to (x2, y2) s1 = sqrt(pow (x2 - x1, 2) + pow (y2 - y1, 2)); //(x2, y2) to (x3, y3) s2 = sqrt(pow (x3 - x2, 2) + pow (y3 - y2, 2)); //(x3, y3) to (x1, y1) s3 = sqrt(pow (x3 - x1, 2) + pow (y3 - y1, 2)); //check that s1, s2, s3 are all equal if (s1 == s2 && s2 == s3){ cout << "Equilateral Triangle!" << endl; } if(s1 != s2 && s2 != s3 && s3 =! s1){ cout << "scalen triangle!" << endl; } /* check for right triangle. to do so, we must find the 'c' value if pythagorean theorem, which is the longest side in a triangle. */ int biggest = max (s1,max (s2, s3)); bool right = false; if (biggest == s1 && sqrt (pow (s2, 2) + pow (s3, 2)) == s1) right = true; else if (biggest == s2 && sqrt (pow (s1, 2) + pow (s3, 2)) == s1) right = true; else if (biggest == s3 && sqrt (pow (s2, 2) + pow (s1, 2)) == s1) right = true; if (right){ cout << "The triangle is right angle triangle!" << endl; } //end program If there were any confusion, please don't hesitate to ask! :D
4th Oct 2016, 6:26 AM
dragonbro1015
dragonbro1015 - avatar
0
how to check the condition for isosceles
6th Sep 2018, 12:57 PM
Neemkar Rithika