Display the combination of three digits
Sabetodo
Posted messages
127
Status
Membre
-
Gemini -
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();
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 réponses
No but seriously, are you all planning to spend all your pool time asking us to come up with your exercises?!?
Hi,
I don't quite see the point of the triple for loop. For my part, I used the following algorithm (in C#):
I find 120 different results, from 012 to 789.
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.
"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
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
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
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
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.
```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.
```
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.
```