RE: [Dev-C++] Code for all combinations
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Rafael d. V. H. <rde...@in...> - 2003-07-23 06:11:00
|
It's like counting in base 11 (6 digits, in reverse order).
#define MAX 11L*11L*11L*11L*11L*11L // 11^6 -> 1.7e6
...
unsigned long n, m;
int i;
int vect[6]={0};
...
for(n=0; n<MAX; n++) {
m=n;
for(i=5; i>=0; i--) {
vect[i]=m%11;
m/=11;
printf("%ul, ", vect[i]);
}
printf("\n");
}
...
It's easy to "unroll" the inner loop in 6 steps and leave only one loop.
-----Mensaje original-----
De: dev...@li...
[mailto:dev...@li...]En nombre de Rodolfo
Dettorre
Enviado el: miércoles 23 de julio de 2003 6:31
Para: André Macário Barros; Dev-Cpp-Users
Asunto: RE: [Dev-C++] Code for all combinations
Hi,
just curiosity, is that a school assignment? An idea would be to nest six
for statements.
Regards
Rodolfo d'Ettorre
-----Original Message-----
From: André Macário Barros [mailto:and...@su...]
Sent: Wednesday, 23 July 2003 1:54 PM
To: Dev-Cpp-Users
Subject: [Dev-C++] Code for all combinations
Dear Users,
I need to test all possibilities in a specific code.
I couldn´t realize how I can generate theese possibilities with two
for´s.
Here is the problem:
Suppose you have a vector like
int vect[6]={0};
How could be a C code to have (print for example) all possible
combinations in the
six positions from the range 0 to 10?
the output is something like:
0 , 0, 0, 0, 0, 0
1 , 0, 0, 0, 0, 0
2 , 0, 0, 0, 0, 0
...
10, 0, 0, 0, 0, 0
0 , 1, 0, 0, 0, 0
0 , 2, 0, 0, 0, 0
...
0 ,10, 0, 0, 0, 0
1, 1, 0, 0, 0, 0
2, 1, 0, 0, 0, 0
...
10, 1, 0, 0, 0, 0
1 , 2, 0, 0, 0, 0
2 , 2, 0, 0, 0, 0
...
10, 2, 0, 0, 0, 0
...
...
10,10,10,10,10,10
Some repetition values are allowed, that is, if you have to
reset all values to begin the counting to another digit, etc.
Regards
Andre
-------------------------------------------------------
This SF.net email is sponsored by: VM Ware
With VMware you can run multiple operating systems on a single machine.
WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
same time. Free trial click here: http://www.vmware.com/wl/offer/345/0
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
-------------------------------------------------------
This SF.net email is sponsored by: VM Ware
With VMware you can run multiple operating systems on a single machine.
WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
same time. Free trial click here: http://www.vmware.com/wl/offer/345/0
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|