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

Turbo Pascal Discussion :

Erreur dans une procédure de tri


Sujet :

Turbo Pascal

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    Lycéen
    Inscrit en
    Mars 2021
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 23
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Lycéen
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mars 2021
    Messages : 1
    Par défaut Erreur dans une procédure de tri
    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
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    Program  ex1;
    uses WinCrt;
    Type
    couple = Record
    x,y:Integer
    end;
    element = Record
    pgcd,ppcm,min,max,a,c:Integer;
    p:LongInt;
    end;
    tab1=array [1..40] of couple;
    tab2=array [1..40] of element;
    var n,i:Integer; t:tab1; r:tab2; f:text;      x,y:Integer;
    Procedure saisir(var n:Integer);
    Begin
    Repeat
    writeln('donner n');
    readln(n);
    until n in [1..40];
    end;
    Procedure rempliar( t:tab1  ;var r:tab2; n:integer);
    var i:Integer;
    Begin
    for  i:=1  to n Do
    Repeat
    writeln('tapez x');
    readln(t[i].x);
    writeln('tapez y');
    readln(t[i].y);
    until ((t[i].y > 0 ) and (t[i].y > 0 ) );
    end;
    Function fact(x:Integer):LongInt;   var f:Integer;
    Begin
    f:=1;
    for i:=1 to n Do
    f:=f*i;
    fact:=f;
    end;
    Function pgcd(x,y:integer):Integer;
    Begin
     
    end;
    Function ppcm(x,y:Integer):integer;
    Begin
    end;
    function min(x,y:Integer):integer;
    Begin
    end;
    Function Max(x,y:Integer):integer;
    Begin
    End;
    Function arrang(x,y:Integer):integer;
    var a:Integer;
    Begin
    a:=1;
    for i:=(y-x+1) to y Do
    a:=a*1;
    arrang:=a;
    end;
    Function combinaison(x,y:Integer):integer;
    Begin
    combinaison:=fact(y)div(fact(x)*fact(y)div fact(y-x));
    end;
    Function puissance(x:real;y:Integer):real;
    var p:real;
    Begin
    p:=1;
    for i:=1 to  abs(y)Do
    p:=p*x;
    if y<0 then
    p:=1/p;
    puissance:=p;
    End;
    Procedure calculer(var t:tab1;r:tab2;n:Integer);
    Begin
    writeln('le calculer est ',pgcd(x,y));
    writeln('le ppcm est = ' ,ppcm(x,y));
    writeln('le minmum est = ',min(x,y));
    writeln('lemaximum est = ' ,max(x,y));
    writeln('larrangement est = ',arrang(x,y));
    writeln('le combinaison est = ',combinaison(x,y));
    writeln('le puissance est = ',puissance(x,y));
    end;
    Procedure tri(r:tab2;var t:tab1;n:Integer);
    var p,aux,kes:Integer;
    Begin
    p:=0;
    for i:=1 to (n-1) do
    if r[i].pgcd > r[i+1].pgcd Then
    p:=p+1;
    aux:=r[i];
    r[i]:=r[i+1];
    r[i+1]:=aux;
    kes:=t[i];
    t[i]:=t[i+1];
    t[i+1]:=kes;
    end;
    Procedure stock(var f:text;t:tab1;r:tab2;n:Integer);
    Begin
    for i:=1 to n Do
    writeln(f,t[i].x,'|',t[i].y,'#',r[i].pgcd,'|',r[i].ppcm,'#',r[i].min ,'|',r[i].max,'#',r[i].a,'|',r[i].c,'|',r[i].p);
    end;
    Begin
    assign(f,'ftnit.txt');
    saisir(n);
    rempliar(t,r,n);
    calculer(t,r,n);
    tri(t,r,n);
    stock(f,t,r,n);
    end.
    Mon problème est que mon module de tri ne fonctionne pas.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    Procedure tri(r:tab2;var t:tab1;n:Integer);
    var p,aux,kes:Integer;
    Begin
    p:=0;
    for i:=1 to (n-1) do
    if r[i].pgcd > r[i+1].pgcd Then
    p:=p+1;
    aux:=r[i];
    r[i]:=r[i+1]; // ici le problème
    r[i+1]:=aux;
    kes:=t[i];
    t[i]:=t[i+1];
    t[i+1]:=kes;
    end;
    Error 26: Type mismatch
    This error occurs because of one of the following:
    • The types of the expression and the variable in an assignment statement are incompatible.
    • The type of the actual and the formal parameters when calling a procedure or function are incompatible.
    • Indexing an array with an expression type incompatible with the index type.
    • Using incompatible types of operands in an expression.

  2. #2
    Rédacteur/Modérateur

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 171
    Billets dans le blog
    9
    Par défaut
    Bonjour !

    Pour commencer, il manque au moins un begin et un end. Voici votre code, mieux présenté pour vous faire voir l'erreur:

    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
    Procedure tri(r:tab2;var t:tab1;n:Integer);
    var p,aux,kes:Integer;
    Begin
      p:=0;
     
      for i:=1 to (n-1) do
        if r[i].pgcd > r[i+1].pgcd Then
          p:=p+1;
     
      aux:=r[i]; // à partir d'ici la valeur de i est indéterminée
      r[i]:=r[i+1];
      r[i+1]:=aux;
      kes:=t[i];
      t[i]:=t[i+1];
      t[i+1]:=kes;
    end;
    D'autre part la variable i devrait être déclarée dans la procédure, et non pas au début du programme.

    Après, il y a peut-être d'autres choses à corriger.

Discussions similaires

  1. Besoin d'aide s'il vous plait
    Par miktifo dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 06/11/2008, 22h22
  2. besoin d'aide s'il vous plait
    Par shinchan95'971 dans le forum Flash
    Réponses: 1
    Dernier message: 11/04/2008, 11h46
  3. AIDE S'IL VOUS PLAIT
    Par valencia 14 dans le forum Modélisation
    Réponses: 1
    Dernier message: 26/03/2008, 21h09
  4. javascript et mon formulaire et ma table de l'aide s'il vous plait
    Par chochatown dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 23/04/2007, 09h12

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