How do I show odd and even numbers of a C array? [closed]

-2

The program consists of an array of 10 numbers, and I ask for a number, if that number is tango to show all the even numbers of the array and its average, and if it is odd, the same, how can I do it only using?

    
asked by Sarah Delgado 08.09.2018 в 00:32
source

1 answer

1

To determine if a number is even, you must check whether by plotting its module with respect to 2, it becomes null. That is, every even number verifies in C:

int numero;

if (numero % 2 == 0) //Par...

In any other case, with any other rest other than zero, the number is odd. If you are not familiar with this type of operation, I would recommend a less superficial study of modular arithmetic. It is a very useful tool in very diverse problems, very far from pure mathematics.

Continuing with your question, in case your vector is not ordered in any way or save a particular distribution, I can not think of any solution other than checking the parity of each element to ensure it. I would simply go through the vector and select those with equal parity as the initial number.

    
answered by 08.09.2018 / 01:03
source