delphi 判断奇数偶数
procedure TForm2.Button2Click(Sender: TObject);
var x: Integer;
begin
x := 1;
if Odd(x) then
ShowMessage(' x 是奇数')
else
ShowMessage(' x 是偶数');
x := 2;
if (x mod 2)=0 then
ShowMessage(' x 是偶数')
else
ShowMessage(' x 是奇数');
end;
procedure TfrmMain.Button1Click(Sender: TObject);
var
i: Integer;
strTemp1, strTemp2: string;
begin
strTemp1 := '';
strTemp2 := '';
Edit2.Text := strTemp1;
Edit3.Text := strTemp2;
for i := 1 to StrToInt(Trim(Edit1.Text)) do
begin
if i mod 2 <> 0 then
strTemp1 := strTemp1 + IntToStr(i) + ','
else
strTemp2 := strTemp2 + IntToStr(i) + ',';
end;
Edit2.Text := strTemp1;
Edit3.Text := strTemp2;
end;
delphi 判断奇数偶数
if x mod 2=0 then write('偶数') else write('奇数');
|
请发表评论