Calcula o fatorial em Delphi de um número digitado pelo usuário.
Enviado: quinta mar 20, 2025 5:17 am
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
EditNumero: TEdit;
ButtonCalcular: TButton;
LabelResultado: TLabel;
Label1: TLabel;
procedure ButtonCalcularClick(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ButtonCalcularClick(Sender: TObject);
var
Numero, i: Integer;
Fatorial: Int64;
begin
Numero := StrToInt(EditNumero.Text);
Fatorial := 1;
for i := 1 to Numero do
Fatorial := Fatorial * i;
LabelResultado.Caption := 'Fatorial de ' + IntToStr(Numero) + ' é ' + IntToStr(Fatorial);
end;
end.
=============================================================
https://www.nasciweb.com.br
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
EditNumero: TEdit;
ButtonCalcular: TButton;
LabelResultado: TLabel;
Label1: TLabel;
procedure ButtonCalcularClick(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ButtonCalcularClick(Sender: TObject);
var
Numero, i: Integer;
Fatorial: Int64;
begin
Numero := StrToInt(EditNumero.Text);
Fatorial := 1;
for i := 1 to Numero do
Fatorial := Fatorial * i;
LabelResultado.Caption := 'Fatorial de ' + IntToStr(Numero) + ' é ' + IntToStr(Fatorial);
end;
end.
=============================================================
https://www.nasciweb.com.br