Problem :
Even, Odd, Positive and Negative
Adapted by Neilor Tonin, URI
Brazil
Timelimit: 1
Brazil
Make a program that reads five integer values. Count how many of these values are even, odd, positive and negative. Print these information like following example.
Input
The input will be 5 integer values.
Output
Print a message like the following example with all letters in lowercase, indicating how many of these values are even, odd, positive and negative.
| Sample Input | Sample Output |
| -5 0 -3 -4 12 | 3 valor(es) par(es) 2 valor(es) impar(es) 1 valor(es) positivo(s) 3 valor(es) negativo(s) |
Solution:
#include <cstdio>int main(){ int c = 5, x, p = 0, n = 0, e = 0, o = 0; while(c--){ scanf("%d", &x); if (x < 0) n++; else if (x > 0) p++; if (x % 2 == 0) e++; else o++; } printf("%d valor(es) par(es)\n", e); printf("%d valor(es) impar(es)\n", o); printf("%d valor(es) positivo(s)\n", p); printf("%d valor(es) negativo(s)\n", n);}
No comments:
Post a Comment