fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // Read a number N (how many numbers you will check).
  5. // Set counters for even, odd, positive, and negative numbers to zero.
  6. // Repeat N times:
  7. // Read a number.
  8. // If the number is even, increase the even counter. Otherwise, increase the odd counter.
  9. // If the number is positive, increase the positive counter. If it is negative, increase the negative counter.
  10. // Print the counts for even, odd, positive, and negative numbers.
  11.  
  12.  
  13. int main() {
  14. int N;
  15. cin >> N;
  16. // 1- Read the number of values
  17.  
  18. int evenCount = 0;
  19. int oddCount = 0;
  20. int positiveCount = 0;
  21. int negativeCount = 0;
  22.  
  23. for (int i = 0; i < N; ++i) {
  24. int number;
  25. cin >> number; // Read each number
  26.  
  27. // Count even and odd
  28. if (number % 2 == 0) {
  29. evenCount++;
  30. } else {
  31. oddCount++;
  32. }
  33.  
  34. // Count positive and negative
  35. if (number > 0) {
  36. positiveCount++;
  37. } else if (number < 0) {
  38. negativeCount++;
  39. }
  40. }
  41.  
  42. // Output the results
  43. cout << "Even: " << evenCount << endl;
  44. cout << "Odd: " << oddCount << endl;
  45. cout << "Positive: " << positiveCount << endl;
  46. cout << "Negative: " << negativeCount << endl;
  47.  
  48. return 0;
  49. }
  50.  
  51. /// + + + +
  52. // + + +
  53. //
  54.  
  55. // ****
  56. // ***
  57. // **
  58. // *
  59. // +
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Even: 0
Odd: 0
Positive: 0
Negative: 0