# Thread: Displaying a table using nested loops

1. ## Displaying a table using nested loops

OBS! no need for nested loops as it seems!

Hi, we got this assignment from the teacher and still after trying and trying and reading I cant solve it. The mission is to display this(ASCII table):

the problem is in the looping itself.

As you see it is 6 rows and 8 columns and as Iunderstand it I need to make the program read from left to right at each line.

this is the code I am playing with right now .. any help if truly very HELPFUL!

Code:
```#include <stdio.h>

int main()
{

char ch='h';

int j;
int i;

for(i=1; i<=6;  i++)
{

for(j=32; j<=78; j++)
{

printf(" %#o ", j );
}

printf("\n");
}	return 0;

}```
I have tried to put the 32-78 in the outher loop but it doesnt work

/Kalle

2. Try to come up with an algorithm. The inner loop goes column-wise, the outer loop goes row-wise while incrementing "ch" thro' every pass of the inner loop and displaying the "ch" value in octal and as a character.

Hint: octal 40 stands for the ASCII space character ' ' not 'h'.

3. Originally Posted by itCbitC
Try to come up with an algorithm. The inner loop goes column-wise, the outer loop goes row-wise while incrementing "ch" thro' every pass of the inner loop and displaying the "ch" value in octal and as a character.

Hint: octal 40 stands for the ASCII space character ' ' not 'h'.

thank you for the help, I am aware about the relation between octal,decimal and character.. that is not hte hard part. I have already displayed the whole table of the ASCII but simply it is just not in a "table form"

for instance I can do this:

Code:
```#include <stdio.h>

int main()
{

char ch='h';

int j;
int i;

for(i=32; i<=78;  i++)
{

printf("%#o %c\t",i,i);

}	return 0;
}```

4. So at some point you're going to have to think. How do you want your table to print? If you are going to insist on nested loops (I don't know why you would, but that's your title) then you need to think what is the purpose of the outer loop (which will tell you (a) what the start-stop numbers are going to be and (2) what goes inside it) and what is the purpose of the inner loop (which will tell you ditto).

5. Originally Posted by tabstop
So at some point you're going to have to think. How do you want your table to print? If you are going to insist on nested loops (I don't know why you would, but that's your title) then you need to think what is the purpose of the outer loop (which will tell you (a) what the start-stop numbers are going to be and (2) what goes inside it) and what is the purpose of the inner loop (which will tell you ditto).

sorry, I could be very wrong.. I shoudnt use any nested loops .. the teacher confused us. I checked now and there are nothing about using nested loop for the solution. it says only printf

6. Did you even read my previous post? You can do it with just one loop if you break onto a new line at column number 8.

7. Originally Posted by itCbitC
Did you even read my previous post? You can do it with just one loop if you break onto a new line at column number 8.

How does one break onto a new line?

8. Originally Posted by leviterande
How do one break onto a new line?
Print a new line character.

9. Originally Posted by tabstop
Print a new line character.
ah, you just mean simple newline, hmmm I think we missunderstand eachother quite a bit actually

10. I still do not undestand what to change. should it be a nested loop in the first place? I am a newbie into programming

11. Originally Posted by leviterande
I still do not undestand what to change. should it be a nested loop in the first place? I am a newbie into programming
When you want to move to a new line, you need to print a new-line character. The decision on whether to do so is a decision (i.e., an if) and so a nested loop is not involved.

12. I am still trying figure it out:

/*Lab3 Assgnment3. using advanced nested loops to show a ASCII table */

Code:
```#include <stdio.h>

int main()
{

int number;

for(number=32; number<=78; number++)

{

if((number) == (number+8))
{
printf("\n");
}
printf(" %#o %c",number, number );
}

return 0;

}```

it still doesnt work, I dont get any compiling erorrs but the if statement doesnt have effects on the code at all?!

13. Why would the number ever equal itself + 8. That's impossible math right there.

Quzah.

14. Originally Posted by leviterande
I am still trying figure it out:
it still doesnt work, I dont get any compiling erorrs but the if statement doesnt have effects on the code at all?!
Instead of repeating what I just said 5 minutes ago, I'll just post a link.