URI Online Judge | 1041 Coordinates of a Point (Solution)

Problem Link:
https://www.urionlinejudge.com.br/judge/en/problems/view/1041

URI Online Judge | 1041

Coordinates of a Point

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Write an algorithm that reads two floating values (x and y), which should represent the coordinates of a point in a plane. Next, determine which quadrant the point belongs, or if you are over one of the Cartesian axes or the origin (x = y = 0).
If the point is at the origin, write the message "Origem".
If the point is over X axis write "Eixo X", else if the point is over Y axis write "Eixo Y".

Input

The input contains the coordinates of a point.

Output

The output should display the quadrant in which the point is.
Sample InputSample Output
4.5 -2.2Q4
0.1 0.1Q1
0.0 0.0Origem
Solution:
#include <stdio.h>
int main()
{
    double x, y;
    scanf("%lf %lf", &x, &y);
 
    if (x == 0.0 && y == 0.0)
    {
        printf("Origem\n");
    }
    else if (x == 0.0 && y != 0.0)
    {
        printf("Eixo Y\n");
    }
    else if (y == 0.0 && x != 0.0)
    {
        printf("Eixo X\n");
    }
    else if (x > 0.0)
    {
        if (y > 0.0)
        {
            printf("Q1\n");
        }
        else printf("Q4\n");
    }
 
    else if (y > 0.0)
    {
        printf("Q2\n");
    }
    else printf("Q3\n");
     
    return 0;
}

Comments

  1. This solution showing wrong answer

    ReplyDelete
  2. #include
    int main()
    {
    double x, y;
    scanf("%lf %lf", &x, &y);

    if (x == 0.0 && y == 0.0)
    {
    printf("Origem\n");
    }
    else if (x == 0.0 && y != 0.0)
    {
    printf("Eixo Y\n");
    }
    else if (y == 0.0 && x != 0.0)
    {
    printf("Eixo X\n");
    }
    else if (x > 0.0)
    {
    if (y > 0.0)
    {
    printf("Q1\n");
    }
    else printf("Q4\n");
    }

    else if (y > 0.0)
    {
    printf("Q2\n");
    }
    else printf("Q3\n");

    return 0;
    }

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. and one more thing your commented code is showing compilation error

    ReplyDelete
  5. #include
    #include
    using namespace std;
    int main(){
    double X,Y;
    scanf("%lf%lf",&X,&Y);
    if(X==0.0&& Y==0.0){
    printf("Origem");
    }
    else if (X == 0.0 && Y != 0.0)
    {
    printf("Eixo Y\n");
    }
    else if (Y == 0.0 && X != 0.0)
    {
    printf("Eixo X\n");
    }
    if(X>0.0 && Y>0.0){
    printf("Q1\n");
    }if(X<0.0 && Y<0.0){
    printf("Q3\n");
    }
    if(X<0.0 && Y>0.0){
    printf("Q2\n");

    }if(X>0.0 && Y<0.0){
    printf("Q4\n");
    }

    ReplyDelete
  6. Visit https://nurnobishanto.com/

    ReplyDelete

Post a Comment

Popular posts from this blog

URI Online Judge | 1036 Bhaskara's Formula (Solution)

URI Online Judge | 1043 Triangle (Solution)

URI Online Judge | 1042 Simple Sort (Solution)