C Program to Count Occurrence of Positive, Zero and Negative Numbers

C program count the occurrence of positive, negative and zero numbers from a set of array elements entered by the user, just the user entered the elements of the array one by one and display the entered array elements. Check all entered numbers using for loop that the number is greater than 0, less than 0 or equals to zero and their counters count the occurrence and display counts at the end of for loop.  

C Program to Count Occurrence of Positive, Zero and Negative Numbers

Following program ask the user to enter 5 numbers using for loop and C Program to Count Occurrence of Positive, Zero and Negative Numbers, then display the result on the screen:


#include<stdio.h>
int main()
{
 int i, pos=0,neg=0,zero=0,a[5];
 printf("Enter elements in array:\t");
 for(i=0;i<=4;i++)
 {
  printf("\nEnter element number :\t",i+1);
  scanf("%d",&a[i]);
 }
 printf("\nEntered 10 arrray elements are:-\t");
 for(i=0;i<=4;i++)
 {
  printf("\na[%d]=%d\n",i,a[i]);
 }
 for(i=0;i<=4;i++)
 {
  if(a[i]<0 a="" else="" i="" if="" neg="">0)
   {
    pos++;
   }
   else
   {
    zero++;
   }
  }
 }
 printf("\nNumber of positives are = %d",pos);
 printf("\nNumber of negatives are = %d",neg);
 printf("\nNumber of zeros are = %d",zero);
 return 0;
}


When the above c program is compiled and executed, it will produce the following result:



If you have any doubts, Please let me know

Previous Post Next Post

Contact Form