# C++ Program to Count Positive and Negative Numbers Using While Loop

Write a C++ program to count and print the number of negative and positive numbers. Count positive and negative numbers in C++. Negative number in C++. For this problem simple fact you have to know that if the number is greater than zero then the number is positive if the number is less than the number is negative otherwise the number is zero. C++ Program to Count Positive and Negative Numbers Using While Loop.

So for this problem, we have two variables one for a positive number and another for a negative number as I said above we compare the number with zero or if the number is greater than zero we will increase the positive variable by one for a negative increase negative variable by one. Before solving follow

Read: C Program To Check Number Is Positive Or Negative

## C++ Program to Count Positive and Negative Numbers Using While Loop

``````#include <iostream>
using namespace std;

/*C++ program to count positive and negative numbers using while loop*/

int main()
{
int a, i, n, zero = 0, pos = 0, neg = 0;

cout << "Enter The Size of An Array :\n";
cin >> n;

cout << "Enter The Element :\n";
for (i = 0; i < n; i++)
{
cin >> a[i];
}

cout << "Elment in Array is Given Below\n";

i = 0;
while (i < n;)
{
if (a[i] > 0)
pos++;
else if (a[i] < 0)
neg++;
else
zero++;
i++;
}

cout << "\nPositive No. is = " << pos;
cout << "\nNegative No. is = " << neg;
cout << "\nTotal Zero in array is = " << zero;
return 0;

}``````

### Similar to Positive and Negative Numbers

Previous Post
Next Post

#### post written by: Ghanendra Yadav

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.