Signup/Sign In

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.

using namespace std;
int main()
  int a[100],i,n,zero=0,pos=0,neg=0;
 cout<<"Enter The Size of An Array :\n";

  cout<<"Enter The Element :\n";

  cout<<"Elment in Array is Given Below\n";
   else if(a[i]<0)
  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 :
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


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