a program to find the numbers of positive, negative, odd and even numbers in a set of numbers in C
#include <stdio.h>
void main ()
{
int a[100];
int num,i;
printf("How many numbers do you want to enter? : ");
scanf("%d",&num);
fflush(stdin);
for (i=0;i<num;i++)
{
printf("Enter %d number: ",i+1);
scanf("%d",&a[i]);
}
int p=0,n=0,z=0,e=0,o=0;
for(i=0;i<num;i++)
{
if(a[i]>0)
p++;
else if (a[i]<0)
n++;
else
z++;
if(a[i]%2==0)
e++;
else o++;
}
printf("Number of positive numbers entered = %d\n",p);
printf("Number of negative numbers entered = %d\n",n);
printf("Number of zeros entered = %d\n",z);
printf("Number of even numbers = %d\n",e);
printf("Number of odd numbers = %d\n",o);
}
Are there any code examples left?
New code examples in category C
-
C 2022-03-27 22:30:45 Problem Statement Print the following output: \ Input Format IN Output Format \
-
C 2022-03-27 18:30:08 how to free memory in c
-
C 2022-03-27 18:00:14 linux command line windows
-
C 2022-03-27 18:00:02 C example of if else
-
C 2022-03-27 17:10:18 sum of digits in c using for loop
-
C 2022-03-27 12:35:50 replace word in c
-
C 2022-03-27 07:40:11 How to setup a line length marker in vim
-
C 2022-03-27 07:35:09 Multi Select with icons htm;