Dark Mode On/Off

# C++ Program To Check Positive / Negative Number Of An Array

We have to write a program to count Number of the Positive and negative number in a 1-D integer Array. Means you have to count a positive and negative number in an Array

## Check Positive / Negative Number Of An Array 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. So for this problem, we have two variable one for positive number and another for the negative number and 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 negative increase negative variable by one.

``````#include<iostream>
using namespace std;
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";
for(i=0;i<n;i++)
{
if(a[i]>0)
pos++;
else if(a[i]<0)
neg++;
else
zero++;
}
cout<<"\nPositive No. is = "<<pos;
cout<<"\nNegative No. is = "<<neg;
cout<<"\nTotal Zero in array is = "<<zero;
return 0;

}
``````

Enter The Size of An Array :
6
Enter The Element :
2 6 8 -1 0 6
Elment in Array is Given Below

Positive No. is = 4
Negative No. is = 1
Total Zero in array is = 1

## Conclusion

Here, in this tutorial, we have learned how to write program for the number of positive and negative numbers in the given array.