Q:

# C++ Program For Count Positive And Negative Number in An Array

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

Logic:-

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[100],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;

}``````

Output:

Enter The Size of An Array :

5

Enter The Element :

12

32

-56

0

-4

Elment in Array is Given Below

Positive No. is = 2

Negative No. is = 2

Total Zero in array is = 1