Write a C++ program to print even and odd number in one function and print positive and negative number in another function(Using Class)
Answers
Answered by
0
Explanation:
Reading 20 integer values from the console, during reading, we count the number of positive numbers, then the number of negative numbers will be equal to 20 minus the number of positive numbers, we also count even numbers and zeros.
#include <iostream> using namespace std; int main() { int positive = 0; int even = 0; int zero = 0; for (int i = 0; i < 20; i++) { int num = 0; cin >> num; if (num >= 0) { positive++; } if (num % 2 == 0) { even++; } if (num == 0) { zero++; } } cout << "Number of positive numbers: " << positive << endl; cout << "Number of negative numbers: " << 20 - positive << endl; cout << "Number of odd numbers: " << 20 - even << endl; cout << "Number of even numbers: " << even << endl; cout << "Number of zeros: " << zero << endl; return 0; }
Similar questions