Display the combination of three digits

Sabetodo Posted messages 127 Status Member -  
 Gemini -
Hello,
hi guys. Does anyone have an idea about this exercise: Write a function that displays in ascending order all the
different combinations of three different digits in ascending order. We have:

"012, 013, 014, 015, 016, 017, 018, 019, 023, ..., 789"

987 is not included since we already have 789, 999 does not consist solely of
digits that are exclusively different from one another.

It should be prototyped as follows:

int my_aff_comb();
Configuration: Linux Firefox 1.0.7

8 answers

  1. snakest
     
    No but seriously, are you all planning to spend all your pool time asking us to come up with your exercises?!?
    12
  2. L0ci Posted messages 112 Status Member 30
     
    Hi,
    I don't quite see the point of the triple for loop. For my part, I used the following algorithm (in C#):
     main { for(int i = 0; i < 999; i++) { if(IsAscending(i)) { //Add to my results } } } private bool IsAscending(int i) { //split the 3 digits if(digit1 < digit2 && digit2 < digit3) return true; return false; } 

    I find 120 different results, from 012 to 789.
    4
  3. dna.factory Posted messages 19915 Registration date   Status Moderator Last intervention   1 621
     
    "it will be prototyped: int my_aff_comb();"
    don't dream, we're not going to do it for you, right
    there's no point in giving us all the details
    tell us instead what you've already thought about, how the numbers are recorded (how many numbers are given, etc..)

    otherwise, you'll end up with:
    printf "012, 013, 014, 015, 016, 017, 018, 019, 023, ..., 789";
    --
    for Christmas, give a Bescherelle
    1
    1. Sabetodo Posted messages 127 Status Member 3
       
      I apologize guys. Here's what I've done, but it's not easy:
       int my_aff_comb() { int a,b,c; for(a=0;a<=7;a++) { for(b=1;b<=8;b++) { for(c=2;c<=9;c++) { my_putchar('a''b''c'); my_putchar(';'); } } } } 

      NB: I am forbidden from using the printf and scanf functions.
      0
    2. loupius > Sabetodo Posted messages 127 Status Member
       
      And, what does the function return?
      0
    3. dna.factory Posted messages 19915 Registration date   Status Moderator Last intervention   1 621 > Sabetodo Posted messages 127 Status Member
       
      this only works for all the digits from 0 to 9
      in my opinion, the real interest of the exercise would be to do the same thing for any number of digits between 0 and 9, with each digit possibly being repeated
      the list being entered as a parameter
      for example, it should work if we enter '0,1,1,3,5,5,5,8' through the function
      even worse, it must be able to work if we enter 1,6,2,8,1,0,3,6
      and indeed, there is a bit more work to do than just 3 lousy loops
      --
      for christmas, give a bescherelle as a gift
      0
    4. mariethe > dna.factory Posted messages 19915 Registration date   Status Moderator Last intervention  
       

      I am looking for information on the possible combinations with 3 digits. I am not too good at math. A thousand thanks.

      0
    5. Modératrice
       
      Hello,
      This combination of numbers is for site codes like blablaland and many others. Thank you, the forum is closed!
      0
  4. emr
     
    Les combinaisons de trois chiffres sont des arrangements possibles de trois chiffres différents, généralement dans un ordre spécifique. Par exemple, les combinaisons pourraient inclure des ensembles comme 012, 123, 456, etc. Si tu as besoin d'un exemple spécifique ou de quelque chose de particulier, fais-le moi savoir.
    0
  5. Tekpi
     
    And another one who comes from Epitech!
    Look in the manuals
    0
  6. Gemini
     
    Personally, I couldn't manage to do those, I'm too bad at algorithms :x
    0
  7. yasmoh2010
     
    ```pascal
    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.
    ```
    -1
  8. christ55
     
    what is the exact number of combinations
    -2
    1. fiddy Posted messages 441 Registration date   Status Contributor Last intervention   1 847
       
      You have 720 combinations.
      0