To write a C Program to count total number of positive elements in an array.
- Start the program.
- Read a variable.
- Read the array values n number of times.
- If the array value can be divided by 2 then increment count by 1.
- Display result.
- Stop the program.
#include<stdio.h>
int main()
{
int n,i,a[10],c=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(a[i]>0)
c++;
}
printf("count of positive numbers in array: %d",c);
}
Thus the program to count total number of positive elements in an array has been executed successfully.