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

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.