Write a program to find total number of +ve, -ve, odd and even numbes in an array.

#include<stdio.h>
numbers(int *arr, int n)
{ int i,a=0,b=0,c=0,d=0;
while(n>0)
{ if(*arr < 0) a++;
if(*arr > 0) b++;
if((*arr % 2)==0) c++;
if((*arr % 2)!=0) d++;
n--;
arr++;
}

printf("\nNumber of +ve numbers:: %d\n",b);
printf("\nNumber of -ve numbers:: %d\n",a);
printf("\nNumber of even numbers:: %d\n",c);
printf("\nNumber of odd numbers:: %d\n",d);
}

main()
{
int n, a[100],i=0;
printf("\nEnter the dimension of array::");
scanf("%d",&n);
printf("\nEnter the elments of array:: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
numbers(a,n);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s