Problem :
Coordinates of a Point
Adapted by Neilor Tonin, URI
Brazil
Timelimit: 1
Brazil
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 Input | Sample Output |
| 4.5 -2.2 | Q4 |
| 0.1 0.1 | Q1 |
| 0.0 0.0 | Origem |
Solution:
#include<stdio.h>int main(){float a,b; while(scanf("%f %f",&a,&b)==2){ if(a==0 && b==0) printf("Origem\n"); else if(b==0) printf("Eixo X\n"); else if(a==0) printf("Eixo Y\n"); else if (a>0 && b>0) printf("Q1\n"); else if(a<0 && b>0) printf("Q2\n"); else if(a<0 && b<0) printf("Q3\n"); else printf("Q4\n"); } return 0;}
No comments:
Post a Comment