Well, as it is you have an infinite loop because you use the variable j in three loops that depend on each other. Two increment and one decrements, so you'll most likely not get the output you wanted. My question is this, what exactly do you want this particular code to do? Because I got it to work and the output is as follows:
Code:
1 1
1
2 1
1
3 1
1
1 2
2
2 2
2
3 2
2
1 1
1
1
2 1
1
1
3 1
1
1
4 1
1
1
As you can see that's not very descritive of what the program does Give me an example of what you want it to do and I'll help you do it.
As for the problem with the tabbing, it's difficult to help you when I can't reproduce the problem on my compiler. You said it works fine on Turbo C++ and has problems with MSVC++ 6 and it worked fine for me in MSVC++ 6. Try fiddling with the code and see if you can get rid of a tab in the beginning, something like this:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void){
int i, j, k; /*counter variables*/
int currentTabs, maxTabs = 3;
printf("\t"); /*add this if there is one too FEW tabs on the first line*/
for(i = 1; i <= 8; i *= 2){
currentTabs = maxTabs;
/*determine and print whitespace needed*/
while(currentTabs > 0){
printf("\t");
currentTabs--;
}
if(maxTabs == 3) /*add this and the next line if there is */
printf("\t"); /*too MANY tabs on the first line*/
/*calculate and print numbers. ex:
** 1
** 121
** 12421
**1248421
**(spaces are tabs)
*/
for(j = 1; j <= i; j *= 2){
printf("%d\t", j);
if(j == i && j > 1){
for(k = j / 2; k >= 1; k /= 2)
printf("%d\t", k);
}
}
printf("\n");
maxTabs--;
}
return EXIT_SUCCESS;
}
I commented the areas you should and and if you should add them. Don't put them both or you'll have problems again. Let me know how that works.
-Prelude