URI Online Judge Solution 1115 Quadrant using C Programming Language.
Write a program to read the coordinates (X, Y) of an indeterminate number of points in Cartesian system. For each point write the quadrant to which it belongs. The program finish when at least one of two coordinates is NULL (in this situation without writing any message).
Write a program to read the coordinates (X, Y) of an indeterminate number of points in Cartesian system. For each point write the quadrant to which it belongs. The program finish when at least one of two coordinates is NULL (in this situation without writing any message).
Input
The input contains several tests cases. Each test case contains two integer numbers.
Output
For each test case, print the corresponding quadrant which these coordinates belong, as in the example.
Input Sample | Output Sample |
2 2
3 -2 -8 -1 -7 1 0 2 |
primeiro
quarto terceiro segundo |
Solution using C :
#include <stdio.h>
int main() {
while(1)
{
int x,y;
scanf("%d%d",&x,&y);
if(x==0 || y == 0)
break;
else
{
if(x>0 && y>0)
printf("primeiro\n");
else if(x>0 && y<0)
printf("quarto\n");
else if(x<0 && y>0)
printf("segundo\n");
else if(x<0 && y<0)
printf("terceiro\n");
}
}
return 0;
}
Comments
Post a Comment