How to find out if a number is odd or even?

Asked

Viewed 4,700 times

0

How to find odd and odd pairs from this list?

Sub kati()
For li = 1 To 10
For col = 1 To 10
  • 3

    And where’s the list?

  • Did any of the answers below solve your problem? Do you think you can accept one of them? Check out the [tour] how to do this, if you still don’t know how to do it. This helps the community by identifying the best solution for you. You can only accept one of them, but you can vote for any question or answer you find useful on the entire site.

2 answers

8

2

Idem to the operator Mod, can be done like this (whereas it is a matrix):

If Matriz(li, col) / 2 - Int(Matriz(li, col) / 2) = 0 Then MsgBox Matriz(li, col) & " é Par" Else MsgBox Matriz(li, col) & " é Impar"
  • Very good Leo, I liked it very much, I only had a doubt, I could explain the mathematical operation?

  • Of course, when dividing an integer by 2, if there is no rest it is even, if there is rest it is odd. The equation takes the result of the division by 2 and subtracts from the whole part of this same result, if 0 is that there was no rest, then the number is even; if 0.5 is that it had rest, then the number is odd. For example: 18/2 - INT(18/2) = 9 - 9 = 0 (Even), 23/2 - INT(23/2) = 11,5 - 11 = 0,5 (Odd), that’s it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.