Take 20 integer inputs of an array from the user and print the following
Positive number. Negative number
Odd number. Even number
Number of 0
#include <iostream>
int main()
{
int numbers[20];
int posNumber{ 0 };
int negNumber{ 0 };
int oddNumber{ 0 };
int evenNumber{ 0 };
int zeroNumber{ 0 };
for (int i = 1; i < 21; i++)
{
std::cout << "Enter " << i << " element of the array: ";
std::cin >> numbers[i - 1];
if (numbers[i - 1] == 0)
{
zeroNumber += 1;
}
else
{
if (numbers[i - 1] > 0)
posNumber += 1;
else
negNumber += 1;
if (numbers[i - 1] % 2 == 0)
evenNumber += 1;
else
oddNumber += 1;
}
}
std::cout << "\n";
std::cout << "Positive number: "<<posNumber<< " Negative number: "<<negNumber<<"\n";
std::cout << "Odd number: " << oddNumber << " Even number: " << evenNumber << "\n";
std::cout << "Number of 0: " << zeroNumber << "\n";
return 0;
}
Comments
Leave a comment