how can i write this ?!

Discussion in 'C' started by cooop, Jul 14, 2009.

  1. cooop

    cooop New Member

    Joined:
    Jul 8, 2009
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    Write a program that takes the x-y coordinates of a point in the Cartesian plane and prints a message telling either an axis on which the point lies, or the quadrant in which it is found, or the origin.
    Code:
     
                                  |
                                  |
                            QII   |  QI
                                  |
                                  |
                         -------------------
                                  |
                                  |
                            QIII  |  QIV
                                  |
                                  |
     
    
    Sample lines of output for 4 runs.
    Run #1
    Enter X and Y separated by a space: -1.0 -2.5
    The point (-1.0, -2,5) is in quadrant III
    Run #2
    Enter X and Y separated by a space: 0.0 -4.8
    The point (0.0, 4.8) is on the y axis
    Run #3
    Enter X and Y seperated by a space: 0.0 0.0
    The point (0.0, 0.0) is the origin
    Run #4
    Enter X and Y seperated by a space: 5.2 0.0
    The point (5.2, 0.0) is on the x axis
     
    Last edited by a moderator: Jul 15, 2009
  2. mayjune

    mayjune New Member

    Joined:
    Jun 14, 2009
    Messages:
    814
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Pune,Delhi
    algo :-

    if (x == 0 && y == 0)
    {
    msg = at origin
    }
    else if (x == 0 && y != 0)
    {
    msg = point is on y axis
    }

    else if (x != 0 && y == 0)
    {
    msg = point is on x axis
    }

    else if (x > 0 && y > 0)
    {
    msg = point in Q I
    }

    else if (x > 0 && y < 0)
    {
    msg = point in Q IV
    }

    /*add other if conditions as per requirement*/

    i hope it clears the idea...there maybe other ways to do it too....but this is the simplest way, :)
     
    Last edited: Jul 14, 2009
  3. cooop

    cooop New Member

    Joined:
    Jul 8, 2009
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
  4. mayjune

    mayjune New Member

    Joined:
    Jun 14, 2009
    Messages:
    814
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Pune,Delhi
    no problem...
    after you done this way, try reducing the code, as i said its the simplest way...
    hint :- if inside if...
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice