Count positive, negative and zero values in an array
Program:
#include <stdio.h>
void main()
{
int num[10],i,pos=0,neg=0,zero=0;
for(i=0;i<10;i++)
{
printf("Enter array element: ");
scanf("%d",&num[i]);
if(num[i]>0)
pos=pos+1;
else
if(num[i]<0)
neg=neg+1;
else
zero=zero+1;
}
printf("Positive=%d, Negative=%d, Zero=%d",pos,neg,zero);
}
Output:
Enter array element: -40
Enter array element: -30
Enter array element: -20
Enter array element: -10
Enter array element: 0
Enter array element: 10
Enter array element: 20
Enter array element: 30
Enter array element: 40
Enter array element: 50
Positive=5, Negative=4, Zero=1
Drafted on 🌏 by,
Jal
☮
peace
Comments
Post a Comment