Algorythmes 1-9 chiffres combinaisons possibl

archers Messages postés 9 Statut Membre -  
 toenian -
Bonjour, je cherche un algorythme permettant de me donner toutes les combinaisons possibles de 1-9 je vous remercie à bientot.
Configuration: Windows XP
Internet Explorer 6.0

6 réponses

  1. yasmoh2010
     
    voici un programme pascal qui affiche toutes les combinaisons possibles des caractères numériques (chiffres) ou alphabétiques dans une chaîne ch, sachant que le nombre de combinaisons est égale au factoriel du nombre total des chiffres , exemple pour ch = 123 il existe 3! combinaisons = 6 combinaison= 6 permutations: pour le nombre 123
    le programme affiche 213-231-132-312-321-123

    Program combinaison;
    Uses WinCrt;

    Var ch:string;

    Procedure Remplir (Var ch:string);
    begin
    writeln('donner le nombre');
    Readln(ch);
    End;

    procedure permut(var x,y:char);
    var aux:char;
    begin
    aux:=x;
    x:=y;
    y:=aux
    end;

    function fact(x:integer):integer;
    var f,i:integer;

    begin
    f:=1;
    for i:= 1 to x do
    begin
    f:=f*i ;
    end;
    fact:=f;
    end;

    procedure affichecomb(ch:string);
    var i,n,np:integer;
    begin
    n:=length(ch);
    np:=0;
    repeat

    for i:= 1 to n-1 do
    begin
    permut(ch[i],ch[i+1]);
    np:=np+1;
    write(ch,'-');
    end;
    permut(ch[1],ch[n]);
    write(ch,'-');
    np:=np+1;

    until np =fact(length(ch));
    end;

    begin
    remplir(ch);
    writeln;
    affichecomb(ch);
    end.
    14