Thread: help me out in this pgm...thank you

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    1

    Question 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. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    If they form a straight line or a point, clearly they cannot form the sides of a triangle.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    A basic understanding of geometry is essential -- no-one is going to do the work for you.

    Write it down on paper first.

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    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.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    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. #7
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    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. #8
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by Todd Burch View Post
    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.
    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.

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Quote Originally Posted by King Mir View Post
    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:
    Quote 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. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    But, I think the fact is this:
    Indeed, though quoting Wikipedia does not make it any more authoritative
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Quote Originally Posted by laserlight View Post
    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. #13
    Registered User
    Join Date
    Nov 2006
    Location
    japan
    Posts
    126
    Quote Originally Posted by anon View Post
    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.
    Mac OS 10.6 Snow Leopard : Darwin

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to write image data to binary PGM file format(P5)?
    By tommy_chai in forum C Programming
    Replies: 6
    Last Post: 11-03-2007, 10:52 PM
  2. PGM images
    By bokkie in forum C++ Programming
    Replies: 1
    Last Post: 03-17-2005, 08:48 AM
  3. image convertion jpg -> pgm
    By AtomRiot in forum C++ Programming
    Replies: 5
    Last Post: 01-31-2003, 05:34 PM
  4. how to convet From .PDF to .Txt through C pgm
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 12-08-2001, 02:13 PM
  5. quick question about C Dos text menu pgm i was doing
    By Shadow in forum C Programming
    Replies: 2
    Last Post: 09-16-2001, 10:26 AM