Let Us C (Chapter 8 : Arrays) : Program-2
(b) Twenty-five numbers are entered from the keyboard into an array. Write a program to find out how many of them are positive, how many are negative, how many are even and how many odd.
// Let Us C (Chapter 8 : Arrays) : Program-2
/* Twenty-five numbers are entered from the keyboard into an array. Write a program to find out how many
of them are positive, how many are negative, how many are even and how many odd */
#include<stdio.h>
int arr[25],i,num,j=0,odd=0,even=0,pos=0,neg=0;
void main()
{
clrscr();
printf("Program to find positive/negative/even/odd numbers out of an array\n");
printf("Enter 25 No.s separated by space\n");
for(i=0;i<25;i++)
scanf("%d",&arr[i]);
while(j<25)
{
if(arr[j]%2==0)
even++;
else
odd++;
if(arr[j]<0)
neg++;
else
pos++;
j++;
}
printf("List has %d EVEN, %d ODD, %d POSITIVE & %d NEGATIVE numbers",even,odd,pos,neg);
}
OUTPUT
Comments
Post a Comment