Answers for "a program to find the numbers of positive, negative, odd and even numbers in a set of numbers in C"

C
0

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);
}
Posted by: Guest on June-24-2021

Code answers related to "a program to find the numbers of positive, negative, odd and even numbers in a set of numbers in C"

Code answers related to "C"

Browse Popular Code Answers by Language