Problem :
Solution:
Even or Odd
Adapted by Neilor Tonin, URI Brazil
Timelimit: 1
Read an integer value N. After, read these N values and print a message for each value saying if this value is odd, even, positive or negative. In case of zero (0), although the correct description would be "EVEN NULL", because by definition zero is even, your program must print only "NULL", without quotes.
Input
The first line of input is an integer N (N < 10000), that indicates the total number of test cases. Each case is a integer number X (-107 < X <107)..
Output
For each test case, print a corresponding message, according with the below example. All messages must be printed in uppercase letters and always will have one space between two words in the same line.
Sample Input | Sample Output |
4 -5 0 3 -4 | ODD NEGATIVE NULL ODD POSITIVE EVEN NEGATIVE |
#include <stdio.h>
int
main() {
/**
* Escreva a sua solução aqui
* Code your solution here
* Escriba su solución aquí
*/
int
T,input,i=0;
scanf
(
"%d"
,&T);
while
(i<=T)
{
i++;
while
(i <= T)
{
i++;
scanf
(
"%d"
,&input);
if
(input%2==0 && input>0)
{
printf
(
"EVEN POSITIVE\n"
);
}
else
if
(input%2==0 && input<0)
{
printf
(
"EVEN NEGATIVE\n"
);
}
else
if
(input==0)
{
printf
(
"NULL\n"
);
}
else
if
(input%2 !=0 && input>0)
{
printf
(
"ODD POSITIVE\n"
);
}
else
if
(input%2!=0 && input<0)
{
printf
(
"ODD NEGATIVE\n"
);
}
}
}
return
0;
}
No comments:
Post a Comment