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

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.

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;
}

1. 2. 3. 