Identificar Par ou Impar

Delphi

20/09/2010

Como faço para identificar se um número é par ou impar?
Luiz Junior

Luiz Junior

Curtidas 0

Respostas

Junior Miranda

Junior Miranda

20/09/2010

if ((SeuParametro mod 2) = 0) then
 Showmessage('Par')
else
   Showmessage('Impar')  ;


[]'s
GOSTEI 0
Fábio Cruz

Fábio Cruz

20/09/2010

If Odd(i) then
  ShowMessage('Impar')
else
    ShowMessage('Par');

GOSTEI 0
Deivison Melo

Deivison Melo

20/09/2010

Existe uma função aqui no próprio site:   Verificando se um inteiro é par ou ímpar   Implemente uma função com o seguinte código:   function ParImpar(aNum: Integer): Boolean; begin   Result := ((aNum div 2) = (aNum/2)); end ;   Para testar, basta utilizar o seguinte código:   if ParImpar(5) then   ShowMessage('Par') else   ShowMessage('Ímpar');     Caminho da dica:   https://www.devmedia.com.br/post-939-Dicas-Verificando-se-um-inteiro-e-par-ou-impar.html   download do exemplo:   http://www.clubedelphi.net/dicamacete/ParImpar.zip   Abração,   Emanoel Deivison Recife - PE    
GOSTEI 0
Deivison Melo

Deivison Melo

20/09/2010

Pode também inverter a lógica mencionada em um dos posts acima: if not(Odd(valor)) then  // onde valor e o valor que deseja verificar!!!
  ShowMessage('par');
else
  ShowMessage('ímpar');
GOSTEI 0
POSTAR