Saturday, 31 October 2015

C++ Program To Count Positive And Negative Number in Array

Problem :- Program to count Number of 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 number is greater than zero then number is positive if number is less than number is negative otherwise number is zero .Before solving follow C Program To Check Number Is Positive Or Negative

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

C++ Program To Count Positive And Negative Number in Array

No comments:
Write comments

Recommended Posts × +