delphi中要求像图片中那样,edit1中输入a,edit2中输入b,edit3中输出a!+...+b!=(....)
3个回答
展开全部
function CalcNum(const A:integer):integer;
begin
if A=1 then
result:=1
else
result:= A * CalcNum(A-1);
end;
var
a, b,c, i: Integer;
lStr: string;
begin
a:= StrToInt(Edit1.Text);
b:= StrToInt(Edit2.Text);
c:=0;
if a=b then
begin
c:= 2* CalcNum(a);
lStr:= format('%d!+%d!=%d', [a,a,c]);
end;
if a<b then
begin
for i:= a to b do
begin
c:= c + CalcNum(i);
if i<b then
lStr:= lStr + Format('%d!+', [i])
else
lStr:= lStr + Format('%d!=', [i])
end;
lStr:= lStr + IntToStr(c);
end;
Edit3.Text:= lStr;
end;
begin
if A=1 then
result:=1
else
result:= A * CalcNum(A-1);
end;
var
a, b,c, i: Integer;
lStr: string;
begin
a:= StrToInt(Edit1.Text);
b:= StrToInt(Edit2.Text);
c:=0;
if a=b then
begin
c:= 2* CalcNum(a);
lStr:= format('%d!+%d!=%d', [a,a,c]);
end;
if a<b then
begin
for i:= a to b do
begin
c:= c + CalcNum(i);
if i<b then
lStr:= lStr + Format('%d!+', [i])
else
lStr:= lStr + Format('%d!=', [i])
end;
lStr:= lStr + IntToStr(c);
end;
Edit3.Text:= lStr;
end;
展开全部
procedure TForm1.Button1Click(Sender: TObject);
var
i,j,iBegin,iEnd,iCount,iItem: Integer;
begin
iBegin := StrToIntDef(Edit1.Text,1);
iEnd := StrToIntDef(Edit2.Text,1);
iCount := 0;
for i := iBegin to iEnd do begin
iItem := 0;
for j := 1 to i do begin
if iItem = 0 then iItem := 1;
iItem := iItem * j;
end;
Inc(iCount,iItem);
end;
Edit3.Text := IntToStr(iCount);
end;
var
i,j,iBegin,iEnd,iCount,iItem: Integer;
begin
iBegin := StrToIntDef(Edit1.Text,1);
iEnd := StrToIntDef(Edit2.Text,1);
iCount := 0;
for i := iBegin to iEnd do begin
iItem := 0;
for j := 1 to i do begin
if iItem = 0 then iItem := 1;
iItem := iItem * j;
end;
Inc(iCount,iItem);
end;
Edit3.Text := IntToStr(iCount);
end;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
function jieCheng( a : integer):integer;
begin
if a = 1 then
result := 1
else
result := a * jieCheng(a - 1);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i,n1,n2,tmp,sum : integer;
begin
n1 := strtoint(edit1.Text);
n2 := strtoint(edit2.Text);
if n1 = n2 then
sum := jieCheng(n1) * 2
else
begin
if n1 > n2 then
begin
tmp := n1;
n1 := n2;
n2 := tmp;
end;
sum := 0;
for i := n1 to n2 do
sum := sum + jieCheng(i);
end;
edit3.Text := IntToStr(sum);
end;
begin
if a = 1 then
result := 1
else
result := a * jieCheng(a - 1);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i,n1,n2,tmp,sum : integer;
begin
n1 := strtoint(edit1.Text);
n2 := strtoint(edit2.Text);
if n1 = n2 then
sum := jieCheng(n1) * 2
else
begin
if n1 > n2 then
begin
tmp := n1;
n1 := n2;
n2 := tmp;
end;
sum := 0;
for i := n1 to n2 do
sum := sum + jieCheng(i);
end;
edit3.Text := IntToStr(sum);
end;
追问
您的 “ edit3 ”没显示 a!+....+b!=..
但还是非常感谢您给我提供思路,thanks a lot.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询