[URI Online Judge] – 1074 – Even or Odd

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

Solution:

#include <cstdio>
int main(){
 int q, n;
 scanf("%d", &q);
 while(q--){
 scanf("%d", &n);
 if (n == 0){
 printf("NULL\n");
 continue;
 }
if (n % 2 == 0)
 printf("EVEN ");
 else
 printf("ODD ");
if (n < 0)
 printf("NEGATIVE\n");
 else
 printf("POSITIVE\n");
 }
return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s