<cracking knuckles>
Ok, let's dig into this.
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 a()
and b()
. 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
1. Program isn't that short
2. Logic isn't that deep
3. 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:
for(int i=5;i>0;i--)
{
for(int j=5;j>0;j--)
{
if(j<=i){
We can see clearly that the nested logic within the for loop iterating j is only executed when j is less than or equal to i. This logic is repeated for each loop. Obviously, then, we aren't interested in every …