Ok, let's dig into this.
[QUOTE=prvnkmr449;1328943]As I understand your problem is to minimize this highly nested loop which print the value of 12 variable.
You should note that the program calls two functions [icode]a()[/icode] and [icode]b()[/icode]. So, it is doing more than just printing out the values of variables. At any rate, yes, this seems to be the main push of the program.
Here is my very short program for that but very deep logic is behind that please try to understand the logic behind this first take look too code
- Program isn't that short
- Logic isn't that deep
- Maybe you should present your algorithm in clearer terms instead of slapping the reader with convoluted pure C code and expecting them to follow
long double n_digit= 5;//0,1,2
long double n_var =4;//x,y,z
long double dif_com =pow( n_digit,n_var);
When I got here, I knew we were in for a doozy. I notice that you are calculating the number all possible combination of n-digit numbers in a b-based numbering system. First of all, this is not necessary. Secondly, it is wrong. Let's investigate why
First look at a section of the OP's code:
We can see clearly that the nested logic within the for loop iterating j is only executed [I]when j is less than or equal to i[/I]. This logic is repeated for each loop. Obviously, then, we aren't interested in [B]every possible[/B] ...