2
, . : 5 3 125, 1+2+5=8.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var
n,m,stepen,dlina,summa:int64;
i:integer;
s:string;
begin
n:=strtoint(inputbox('',' , ',''));
m:=strtoint(inputbox('',' ',''));
stepen:=n; // stepen n m
for i:=1 to m-1 do stepen:=stepen*n; //
dlina:=length(inttostr(stepen)); //
label2.Caption:=' '+inttostr(n)+' '+inttostr(m)+' = ';
label4.Caption:=inttostr(stepen);
summa:=0;
for i:=1 to dlina do begin
summa:=summa+strtoint(copy(inttostr(stepen),i,1)); //
end;
label1.Caption:=inttostr(summa); //
end;
end.
: , . . : : , : , , . .
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Button1: TButton;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var i,fact:integer;
begin
fact:=1;
for i:=1 to strtoint(Edit1.Text) do begin
fact:=fact*i;
end;
Label3.Caption:='='+floattostr(fact);
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Button1: TButton;
Label3: TLabel;
|
|
procedure Button1Click(Sender: TObject);
var
Form1: TForm1;
function factor(N:integer):real;
implementation
function factor(N:Integer):real;
begin
if N=1
then Result:= 1
else Result:= N*factor(N-1);
end;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Label3.Caption:=Floattostr(factor(strtoint(Edit1.Text)));
end;
end.