# help me out in this pgm...thank you

This is a discussion on help me out in this pgm...thank you within the C Programming forums, part of the General Programming Boards category; Given three numbers, determine whether they can form the sides of a triangle...the doubt is..how do you actually determine whether ...

1. ## help me out in this pgm...thank you

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....

2. If they form a straight line or a point, clearly they cannot form the sides of a triangle.

3. A basic understanding of geometry is essential -- no-one is going to do the work for you.

Write it down on paper first.

4. 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.

5. 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.

6. 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!

7. 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

8. Originally Posted by Todd Burch
On the other hand, for what it's worth, ANY triangle can be formed with any length sides. Think about it.
Not in Euclidean geometry. 1,2,4 do not form the sides of a triangle.

The sum of the two shorter sides must be greater than the size of the longer size.

@Elysia
Pythagorean theorem only applies to right triangles.

9. 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.

10. Originally Posted by King Mir
Not in Euclidean geometry. 1,2,4 do not form the sides of a triangle.

The sum of the two shorter sides must be less than the size of the longer size.
Oops. Forgot that one. My bad. duh.

But, I think the fact is this:
Originally Posted by Wikipedia
The sum of the lengths of any two sides of a triangle always exceeds the length of the third side.

11. But, I think the fact is this:
Indeed, though quoting Wikipedia does not make it any more authoritative

12. Originally Posted by laserlight
Indeed, though quoting Wikipedia does not make it any more authoritative
I was just taking the focus off of myself. As evident from my first declaration, I obviously didn't pull that out of my back pocket.

Needless to say, I think the OP now has his answer.

13. Originally Posted by anon
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.
That is the answer dude. As someone said... is geometry and not programming. But anon gave you the answer.