URI Online Judge Solution 1041 Coordinates of a Point using C, Python Programming Language.
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.
Input Sample | Output Sample |
4.5 -2.2
|
Q4
|
0.1 0.1
|
Q1
|
0.0 0.0
|
Origem
|
Solution using Python :
X,Y = map(float,input().split())
if X==0.0 and Y==0.0:
print("Origem")
elif X == 0.0 and Y != 0.0:
print("Eixo Y")
elif X!=0.0 and Y == 0.0:
print("Eixo X")
elif X >0.0 and Y > 0.0:
print("Q1")
elif X>0.0 and Y<0.0:
print("Q4")
elif X<0.0 and Y>0.0:
print("Q2")
elif X<0.0 and Y<0.0:
print("Q3")
Solution using C :
#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
Post a Comment