C Programming Code Examples C > Arrays and Matrices Code Examples C program to count total number of negative elements in array C program to count total number of negative elements in array Write a C program to read elements in an array and count total number of negative elements in array. C program to find all negative elements in an array. Logic to count total negative/positive elements in an array Input size and array elements from user. Store it in some variable say n and array. To store count of negative elements, declare and initialize a variable with 0, say count = 0. Run a loop from 0 to n i.e. size of array. The loop structure should look like for(j=0; j<n; j++). Inside the loop check if the current number is negative, then increment the count by 1. Means perform if(array[j] < 0) then, count = count + 1. Finally, after loop you are left with total negative element count. #include <stdio.h> int main() { int array[88]; //Declares an array of size 88 int j, n, count=0; /* Input size of the array */ printf("Enter size of the array : "); scanf("%d", &n); /* Input array elements */ printf("Enter elements in array : "); for(j=0; j<n; j++) { scanf("%d", &array[j]); } /* * Counts total number of negative elements in array */ for(j=0; j<n; j++) { /* Increment count if current array element is negative */ if(array[j]<0) { count++; } } printf("\nTotal number of negative elements = %d", count); return 0; }