Given three numbers, determine whether they can form the sides of a triangle...the doubt is..how do you actually determine whether given inputs form the sides of a triangle??pls help me out...or atleast put in the logic of writing this program....
Given three numbers, determine whether they can form the sides of a triangle...the doubt is..how do you actually determine whether given inputs form the sides of a triangle??pls help me out...or atleast put in the logic of writing this program....
If they form a straight line or a point, clearly they cannot form the sides of a triangle.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
A basic understanding of geometry is essential -- no-one is going to do the work for you.
Write it down on paper first.
The three numbers are the lengths of lines? If three lines should be able to form a triangle the longest line must be shorter than the two remaining lines together.
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
How about Pythagoras equation (or whatever it's called)? If you draw a line from each points and calculate the distance of those lines (using Pythagoras), then determining if you can use Pythagoras and getting a valid answer. In essence, since it should work on all triangles, the lines must form a triangle.
Its not that clear to me what you are asking but if you just mean for example
2, 7, 12
then that seems pretty meaningless, because alone they are just numbers, you have to then assign properties to them, e.g decide that they represent length or maybe points on a plane, but then you would need to define the dimensions of the plane to see if by joining them they could make a triangle. And thus their ability to make a triangle is determined by the other elements you put in the 'scenario'
if the plane was 20 columns wide joining the three points would give a straight line, so no triangle.
you could with these numbers say that >
yPosA = 2 / num_of_rows
xPosA = 2 - num_of_columns * yPosA
this gets you x&y co-ords from the first number
etc for the other two numbers
i think!
The Pythagorean theorem states that for a right triangle, the length of the hypotenuse is the square root of the sum of the squares of the other two sides.
Are we to assume the three numbers are the lengths of the 3 sides?
On the other hand, for what it's worth, ANY triangle can be formed with any length sides. Think about it.
Todd
Last edited by King Mir; 01-30-2008 at 06:47 AM.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
Heh, I assumed co-ordinates where forming the sides involves connecting the points with straight lines, in which case one should check that the points are not collinear. But yeah, if they are lengths of sides, then the problem is just a matter of determining the longest side and checking if it is less than the sum of the lengths of the other two sides.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Indeed, though quoting Wikipedia does not make it any more authoritativeBut, I think the fact is this:
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)