C Program to count numbers of positive negative and zero in the array


In this program, You will learn how to count numbers of positive negative and zero integers in an array in c.


Array elements is: 15, 0, -13, 0, -14

Positive, negative & zero is: 1 2 2

Example: How to count numbers of positive negative and zero integers in array in c.

#include<stdio.h>

int main() {

   int arr[5];
   int pos = 0, neg = 0, zero = 0, i;

   printf("Enter array elements:");
   for (i = 0; i < 5; i++) {
       scanf("%d", &arr[i]);
   }

   for (i = 0; i < 5; i++) {
       if (arr[i] > 0) {
           pos++;
       } else if (arr[i] < 0) {
           neg++;
       } else {
           zero++;
       }
   }
   printf("Positive integers is:%d", pos);
   printf("\nNegative integers is:%d", neg);
   printf("\nZero integers is:%d", zero);

   return 0;
}

Output:

Enter array elements:10 20 -30 0 40                                                                                                    
Positive integers is:3                                                                                                                 
Negative integers is:1                                                                                                                 
Zero integers is:1