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

Problem:- 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 This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.

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. Before solving follow C Program To Check Number Is Positive Or Negative

Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.

Solution:-

#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:-

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

1. Below there is an Array of positive and negative number. Write a program that calculates how many of the numbers are positive and how many of them are negative. A [ ] = {10, -2, 9. -4, -6, -7, 12, 14, 19, -20}

2. You are askig same Query. I think you are searching for C++ Program To Check Number Is Positive Or Negative If you have any Other Query send a Email.

/*
Below there is an Array of positive and negative number. Write a program that calculates how many of
the numbers are positive and how many of them are negative. A [ ] = {10, -2, 9. -4, -6, -7, 12, 14, 19, -20} on
*/

#include
#include

using namespace std;

int main()
{
int n, i,countneg = 0 , countpos = 0, countzero = 0;

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

int arr[n];

cout<<"\nEnter The Array Elements: \n";

for(i = 0; i < n; i++)
{
cin>>arr[i];
}

for(i = 0; i < n; i++)
{
if(arr[i]<0)
{
countneg++;
}
else if(arr[i]>0)
{
countpos++;
}
else
{
countzero++;
}
}

cout<<"\n\nTotal Number of Positive Elements in An Array is: "<<countpos;
cout<<"\nTotal Number of Negative Elements in An Array is: "<<countneg;
cout<<"\nTotal Number of Zero Elements in An Array is: "<<countzero;

return 0;
}