Count Positive and Negative Numbers in an Array in C

In this post, we will have a look at “How to count positive and negative numbers in an array in C Programming language?

#include<stdio.h> 
int main()
{ 
int SizeOfArray, i, a[10]; 
int PositiveCounter  = 0, NegativeCounter  = 0;  
printf("\n Please Enter the SizeOfArray of an Array :  "); 
scanf("%d", &SizeOfArray);  
printf("\nPlease Enter the Array Elements\n"); 
for(i = 0; i < SizeOfArray; i++) 
{      
scanf("%d", &a[i]);
}   
for(i = 0; i < SizeOfArray; i ++) 
{   
if(a[i] >= 0)   
{        
PositiveCounter ++;   
}   
else   
{        
NegativeCounter ++;   
} 
}   
printf("\n Total Count of Positive Numbers in this Array = %d ", PositiveCounter ); 
printf("\n Total Count of Negative Numbers in this Array = %d ", NegativeCounter ); 
return 0;}

Leave a Reply

Shopping cart