Accueil > > > Unit1.pas
PGCD - ALGORITHME D'EUCLIDE
Unit1.pas
Informations sur ce code source
Bon voila je post pour la premiere fois sur ce site mon code source.
Je pense qu'il est assé simple mais bon...
Allez assé discuté se code ne sert a rien d'autre qu'a calculé le PGCD de deux nombre non nul (logique),
par l'algorithme d'Euclide.
Fichier : Unit1.pas
Nombre de lignes : 97 lignes
Afficher ce fichier en plein écran
- unit Unit1;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls;
-
- type
- TForm1 = class(TForm)
- BCalculer: TButton;
- BQuitter: TButton;
- ENB1: TEdit;
- ENB2: TEdit;
- EPGCD: TEdit;
- Label1: TLabel;
- Label2: TLabel;
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure ENB2KeyPress(Sender: TObject; var Key: Char);
- procedure ENB1KeyPress(Sender: TObject; var Key: Char);
- procedure BCalculerClick(Sender: TObject);
- procedure BQuitterClick(Sender: TObject);
- private
- { Déclarations privées }
- public
- { Déclarations publiques }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.dfm}
-
- procedure TForm1.ENB1KeyPress(Sender: TObject; var Key: Char);
- begin
- //N'autorise que les chiffres dans le TEdit
- if not (key in ['0'..'9',#8]) then key := #0;
- end;
-
- procedure TForm1.ENB2KeyPress(Sender: TObject; var Key: Char);
- begin
- //N'autorise que les chiffres dans le TEdit
- if not (key in ['0'..'9',#8]) then key := #0;
- end;
-
-
- procedure TForm1.BCalculerClick(Sender: TObject);
- var
- NB1, NB2, TMP: LONGINT;
- VNB1, VNB2 : BOOLEAN;
- begin
- //Initialisation des variable VNB1 et VNB2 a False
- VNB1 := False;
- VNB2 := False;
-
- //Test pour savoir si le TEdit ENB1 est remplie
- if ENB1.Text = '' then MessageBoxA(0,Pchar('La case du nombre 1 est vide!'),Pchar('Attention...'),0 + MB_ICONEXCLAMATION + 0)
- else begin NB1 := StrToInt(ENB1.Text); VNB1:= True; end;
- //Test pour savoir si le TEdit ENB2 est remplie
- if ENB2.Text = '' then MessageBoxA(0,Pchar('La case du nombre 2 est vide!'),Pchar('Attention...'),0 + MB_ICONEXCLAMATION + 0)
- else begin NB2 := StrToInt(ENB2.Text); VNB2:= True; end;
-
- //Test pour verifier que les deux TEdit son bien remplie
- if ((VNB1 = True) and (VNB2 = True)) then
- begin
- //Le fameux algorithme d'Euclide
- while not (NB2=0) do
- begin
- TMP:=NB1;
- NB1:=NB2;
- NB2:=TMP mod NB2;
- end;
-
- //Test pour savoir si les deux nombre saisi sont nul sinon on affiche le resultat
- if NB1=0 then MessageBoxA(0,Pchar('Pas de PGCD pour 2 nombres nuls!'),Pchar('Attention...'),0 + MB_ICONEXCLAMATION + 0)
- else EPGCD.Text:= 'pgcd('+ENB1.Text+';'+ENB2.Text+')='+IntToStr(NB1)
- end
- end;
-
- procedure TForm1.BQuitterClick(Sender: TObject);
- begin
- //Un p'tit about avant de quitter le programme!
- MessageBoxA(0,Pchar('Créer par charlyb29/6B0RG'+#13+'Pour la team TTuXX @ 2oo6'+#13+''+#13+'Contact: charlyb29@hotmail.com'),Pchar('Quitter...'),0 + MB_ICONINFORMATION + 0);
- Application.Terminate;
- end;
-
- procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- //Un p'tit about avant de quitter le programme!
- MessageBoxA(0,Pchar('Créer par charlyb29/6B0RG'+#13+'Pour la team TTuXX @ 2oo6'+#13+''+#13+'Contact: charlyb29@hotmail.com'),Pchar('Quitter...'),0 + MB_ICONINFORMATION + 0);
- end;
-
- end.
-
|