Fórum Divisao por 2 e 3 #207150
17/01/2004
0
Desde já agradeço a ajuda.
Diegobarcelos
Curtir tópico
+ 0Posts
17/01/2004
Tnaires
if ((StrToInt(Edit1.Text) mod 2 = 0) or (StrToInt(Edit1.Text) mod 3 = 0)) and ((StrToInt(Edit2.Text) mod 2 = 0) or (StrToInt(Edit2.Text) mod 3 = 0)) and ((StrToInt(Edit3.Text) mod 2 = 0) or (StrToInt(Edit3.Text) mod 3 = 0)) and ((StrToInt(Edit4.Text) mod 2 = 0) or (StrToInt(Edit4.Text) mod 3 = 0)) then ShowMessage(Edit1.Text + ´ ´ + Edit2.Text + ´ ´ + Edit3.Text + ´ ´ + Edit4.Text);
Deve haver maneira melhor, mas...
Gostei + 0
17/01/2004
Tnaires
A solução acima é para números divisíveis por 2 ou por 3.
Para números divisíveis por dois e por 3:
if ((StrToInt(Edit1.Text) mod 2 = 0) and (StrToInt(Edit1.Text) mod 3 = 0)) and ((StrToInt(Edit2.Text) mod 2 = 0) and (StrToInt(Edit2.Text) mod 3 = 0)) and ((StrToInt(Edit3.Text) mod 2 = 0) and (StrToInt(Edit3.Text) mod 3 = 0)) and ((StrToInt(Edit4.Text) mod 2 = 0) and (StrToInt(Edit4.Text) mod 3 = 0)) then ShowMessage(Edit1.Text + ´ ´ + Edit2.Text + ´ ´ + Edit3.Text + ´ ´ + Edit4.Text);
OK?
Gostei + 0
17/01/2004
Tnaires
Eu interpretei o seguinte: mostre na tela somente se todos os números forem divisíveis por 2 e por 3.
Mas acho q vc quer q mostre na tela aqueles números divisíveis por 2 e por 3 não é?
Me desculpe o excesso de mensagens, esta é a última:
function NumerosDivisiveisPor2EPor3: string; begin Result := ´´; if (StrToInt(Edit1.Text) mod 2 = 0) and (StrToInt(Edit1.Text) mod 3 = 0) then Result := Result + Edit1.Text + ´ ´; if (StrToInt(Edit2.Text) mod 2 = 0) and (StrToInt(Edit2.Text) mod 3 = 0) then Result := Result + Edit2.Text + ´ ´; if (StrToInt(Edit3.Text) mod 2 = 0) and (StrToInt(Edit3.Text) mod 3 = 0) then Result := Result + Edit3.Text + ´ ´; if (StrToInt(Edit4.Text) mod 2 = 0) and (StrToInt(Edit4.Text) mod 3 = 0) then Result := Result + Edit4.Text + ´ ´; Result := Trim(Result); end;
No OnClick do botão:
ShowMessage(NumerosDivisiveisPor2EPor3);
Mais uma vez, peço desculpas.
Gostei + 0
17/01/2004
Diegobarcelos
Gostei + 0
17/01/2004
Marco Salles
Este Número For Divisível Por [color=red:9c7a9ad308]SEIS[/color:9c7a9ad308]. Então Sugiro Que o Código Fique Mais Simplificado ..
function NumerosDivisiveisPor2EPor3: string;
begin
Result := ´´;
if (StrToInt(Edit1.Text) mod 6 = 0)
Result := Result + Edit1.Text + ´ ´;
if (StrToInt(Edit2.Text) mod 6 = 0)
Result := Result + Edit2.Text + ´ ´;
if (StrToInt(Edit3.Text) mod 6 = 0)
Result := Result + Edit3.Text + ´ ´;
if (StrToInt(Edit4.Text) mod 6 = 0) and
Result := Result + Edit4.Text + ´ ´;
Result := Trim(Result);
end;
No OnClick do botão:
Código:
ShowMessage(NumerosDivisiveisPor2EPor3);
Espero Ter Contribuido....
Gostei + 0
17/01/2004
Tnaires
Impressionante como um detalhe matemático pode simplificar drasticamente o código... :wink:
Sucesso a todos nós
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)