counter

Free Hit Counter

Counting of array elements

Q: nos are entered thru the keyboard and the no. of positive,negative and zero elements also the count of odd and even nos present in the array are displayed


#include
#include
void main()
{
int a[25],i,z=0,p=0,n=0,o=0,e=0;
clrscr();
for(i=0;i<5;i++)
{
printf("enter any no.:");
scanf("%d",&a[i]);
}

for(i=0;i<5;i++)
{

if(a[i]==0)
z++;
else if(a[i]>0)
p++;
else
n++;
}
for(i=0;i<5;i++)
{
if(a[i]%2==0)
e++;
else
o++;
}
printf("no of Zero elements:%d\n",z);
printf("no of positive nos:%d\n",p);
printf("no of negative nos:%d\n",n);
printf("no of odd nos:%d\n",o);
printf("no of even nos:%d\n",e);

getch();
}



No comments:

Post a Comment