C++ Programming Code Examples C++ > If Else and Switch Case Code Examples Count Occurrence of Positive, Zero and Negative Numbers Count Occurrence of Positive, Zero and Negative Numbers To count the number of positive number, negative number, and zero from the given set of numbers entered by the user in C++ programming, you have to ask to the user to enter some set of numbers (10 numbers here). Now to find occurrence of positive, negative and zero from the given set of numbers, just check all the numbers using for loop whether the number is 0, less than zero or greater than 0 to count the occurrence of positive, negative and zero as shown here in the following program. Following C++ program ask to the user to enter 10 numbers to check for number of positive number, negative number and zero occurrence, then display the result on the screen: /* C++ Program - Count Occurrence of Numbers */ #include<iostream.h> #include<conio.h> void main() { clrscr(); int countp=0, countn=0, countz=0, arr[10], i; cout<<"Enter 10 numbers : "; for(i=0; i<10; i++) { cin>>arr[i]; } for(i=0; i<10; i++) { if(arr[i]<0) { countn++; } else if(arr[i]==0) { countz++; } else { countp++; } } cout<<"Positive Numbers = "<<countp<<"\n"; cout<<"Negative Numbers = "<<countn<<"\n"; cout<<"Zero = "<<countz<<"\n"; getch(); }