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

0

How do I find even and odd numbers in this list?

Sub kati()
For li = 1 To 10
For col = 1 To 10
    
asked by anonymous 02.07.2016 / 17:03

2 answers

8

Use the Mod operator . If the remainder of the division by 2 is 0, then the number is even. Example:

If li Mod 2 = 0 then 'faça o que quiser aqui
If col Mod 2 = 0 then 'faça o que quiser aqui
    
02.07.2016 / 17:08
2

Same as the Mod operator, it can be done this way (considering it is an array):

If Matriz(li, col) / 2 - Int(Matriz(li, col) / 2) = 0 Then MsgBox Matriz(li, col) & " é Par" Else MsgBox Matriz(li, col) & " é Impar"
    
02.07.2016 / 19:22