C Program to count numbers of positive negative and zero in 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

Run it Now
#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("\nPositive Integers is :%d", pos);
   printf("\nNegative Integers is :%d", neg);
   printf("\nZero Integers is :%d", zero);

   return 0;
}

Output:

Enter Array Elements :15 0 -13 0 -14
Positive Integers is :1
Negative Integers is :2
Zero Integers is :2