IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Flash Pascal Discussion :

Triangle de Pascal


Sujet :

Flash Pascal

  1. #1
    Rédacteur/Modérateur

    Avatar de Roland Chastain
    Homme Profil pro
    Enseignant
    Inscrit en
    Décembre 2011
    Messages
    4 062
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 062
    Points : 15 353
    Points
    15 353
    Billets dans le blog
    9
    Par défaut Triangle de Pascal
    Bonjour ! Voici un programme qui construit et affiche un triangle de Pascal.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
     
    program TrianglePascal;
     
    uses Flash8;
     
    {$FRAME_WIDTH 1200}
    {$FRAME_HEIGHT 600}
    {$BACKGROUND 0}
     
    const
      LARGEUR = 1200;
      HAUTEUR = 600;
      VER = 'Compilateur FlashPascal 2 v14.04.22'#13;
     
    var
      t: TextField;
      f: TextFormat;
      s: string;
     
    function IntToLStr(i, l: integer; char: string): string;
    begin
      result := IntToStr(i);
      while length(result) < l do
        result := char + result;
    end;
     
    const
      N = 17;
     
    var
      tr: array[1..N, 1..N]of integer;
     
    procedure Calcule(const aX, aY: integer);
    begin
      if aX + aY <= N + 1 then
      begin
        tr[aX, aY] := tr[aX - 1, aY] + tr[aX, aY - 1];
        Calcule(aX, aY + 1);
        Calcule(aX + 1, aY);
      end;
    end;
     
    var
      x, y: integer;
     
    begin
      f := TextFormat.Create('Courier New', 16);
      f.color := clWhite;
      f.leftMargin := 5;
      t := TextField.Create(_root, 't', 0, 0, 0, LARGEUR, HAUTEUR);
      t.SetNewTextFormat(f);
     
      for x := 1 to N do
        tr[x, 1] := 1;
      for y := 1 to N do
        tr[1, y] := 1;
     
      Calcule(2, 2);
     
      s := '';
     
      for y := 1 to N do
      begin
        for x := 1 to N do
          if x + y <= N + 1 then
            s := s + IntToLStr(tr[x, y], 6, ' ');
        s := s + #13;
      end;
     
      t.text := VER + s;
      f.size := 12;
      f.color := clLime;
      t.SetTextFormat(0, Length(VER) - 1, f);
    end.
    Mon site personnel consacré à MSEide+MSEgui : msegui.net

  2. #2
    Rédacteur/Modérateur

    Avatar de Roland Chastain
    Homme Profil pro
    Enseignant
    Inscrit en
    Décembre 2011
    Messages
    4 062
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 062
    Points : 15 353
    Points
    15 353
    Billets dans le blog
    9
    Par défaut
    Le même triangle, construit par une autre méthode plus rapide.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
     
    program TrianglePascal2;
     
    uses Flash8;
     
    {$FRAME_WIDTH 1200}
    {$FRAME_HEIGHT 600}
    {$BACKGROUND 0}
     
    const
      LARGEUR = 1200;
      HAUTEUR = 600;
      VER = 'Compilateur FlashPascal 2 v14.04.22'#13;
     
    var
      t: TextField;
      f: TextFormat;
      s: string;
     
    function IntToLStr(i, l: integer; char: string): string;
    begin
      result := IntToStr(i);
      while length(result) < l do
        result := char + result;
    end;
     
    const
      N = 17;
     
    var
      tr: array[1..N, 1..N]of integer;
     
    var
      x, y: integer;
     
    begin
      f := TextFormat.Create('Courier New', 16);
      f.color := clWhite;
      f.leftMargin := 5;
      t := TextField.Create(_root, 't', 0, 0, 0, LARGEUR, HAUTEUR);
      t.SetNewTextFormat(f);
     
      for x := 1 to N do
        tr[x, 1] := 1;
      for y := 1 to N do
        tr[1, y] := 1;
     
      x := 2;
      y := 2;
      repeat
        tr[x, y] := tr[x - 1, y] + tr[x, y - 1];
        Inc(x);
        Dec(y);
        if y = 1 then
        begin
          y := x;
          x := 2;
        end;
      until (x = 2) and (y = N);
     
      s := '';
      for y := 1 to N do
      begin
        for x := 1 to N do
          if x + y <= N + 1 then
            s := s + IntToLStr(tr[x, y], 6, ' ');
        s := s + #13;
      end;
     
      t.text := VER + s;
      f.size := 12;
      f.color := clLime;
      t.SetTextFormat(0, Length(VER) - 1, f);
    end.
    Mon site personnel consacré à MSEide+MSEgui : msegui.net

  3. #3
    Rédacteur/Modérateur

    Avatar de Roland Chastain
    Homme Profil pro
    Enseignant
    Inscrit en
    Décembre 2011
    Messages
    4 062
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 062
    Points : 15 353
    Points
    15 353
    Billets dans le blog
    9
    Par défaut
    Le même programme mais les résultats sont présentés dans un tableau. Merci à Archimède pour son composant TStringGrid.
    Fichiers attachés Fichiers attachés
    Mon site personnel consacré à MSEide+MSEgui : msegui.net

  4. #4
    Membre chevronné
    Avatar de Archimède
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2005
    Messages
    1 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Points : 1 975
    Points
    1 975
    Par défaut
    Sympa

Discussions similaires

  1. Affichage du Triangle de Pascal
    Par jrosenzw dans le forum C++
    Réponses: 11
    Dernier message: 14/03/2009, 04h10
  2. Triangle de pascal
    Par koko03 dans le forum Mathématiques
    Réponses: 3
    Dernier message: 26/01/2009, 18h52
  3. triangle de pascal
    Par chouuc dans le forum Algorithmes et structures de données
    Réponses: 9
    Dernier message: 20/01/2009, 02h36
  4. Triangle de Pascal
    Par WhiteTigerZ dans le forum Pascal
    Réponses: 5
    Dernier message: 09/03/2007, 20h47
  5. Triangle de Pascal
    Par yushkoya dans le forum VBScript
    Réponses: 6
    Dernier message: 11/07/2006, 15h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo