Monday, 19 August 2013

Chapter 8 solutions Problem [D][b]

Question-Twenty-five numbers are entered from the keyboard into an
array.Write a program to find out how many of themare 
positive, how many are negative, how many are even and how 
many odd.
Solution-
just similar question,with one or two changes.

#include<stdio.h>
#define m 25
int main()
{
int array[m],i,p=0,n=0,o=0,e=0;
printf("Enter any 25 numbers\n");
for(i=0;i<=m-1;i++)
scanf("%d",&array[i]);
for(i=0;i<=m-1;i++)
{
if(array[i]>0)
p++;
if(array[i]<0)
n++;
if(array[i]%2==0)
e++;
if(array[i]%2!=0)
o++;
}
printf("Positive numbers=%d\nNegative number=%d\n",p,n);
printf("Even Number=%d\nOdd numbers=%d\n",e,o);
return 0;
}

No comments:

Post a Comment