# Thread: Multiplication Table using loops

1. ## Multiplication Table using loops

Hi there,

I need some help with formatting on my program. I can't seem to get the table to look like this:

Code:
```
1   2   3   4
-------------------
1     1   2   3   4
2     2   4   6   8
3     3   6   9  12
4     4   8  12  16```
Here is my code:

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

int mult(int x, int y);

int main(void)

{
int x, y;

for (x = 1; x < 10; x++)  {
printf("%4d", x);
}
printf("\n");
printf("-------------------------------------\n");

for (y = 1; y < 10; y++)  {
printf("%d\n", y);
}

for (x = 1; x < 10; x++)   {
for (y = 1; y < 10; y++)    {
printf("%4d", mult(x, y));
}
}
return (0);
}

int mult(int x, int y)
{
return(x * y);
}```
Now, I realize this would be 100x easier with arrays, but we haven't learned them in class yet, so I need to use loops. I just don't know how to get the numbers I need on the lines I want, like shown above.

Help/Tips appreciated.

2. Make your "%d" fields bigger... maybe 6 instead of 4... then put a printf("\n"); at line 32... moving the brace to 33.

And in this case... arrays would be overkill, and present you with the same formatting problems.

3. Code:
``` for (y = 1; y < 10; y++)  {
printf("%d\n", y);
}

for (x = 1; x < 10; x++)   {
for (y = 1; y < 10; y++)    {
printf("%4d", mult(x, y));
}
}```
Well at this part of the code in your top loop you are printing a single number followed by a new line. When that's complete you are then printing your multiplication table, so you must combine them in one loop.

4. @lolcats... please don't back edit your first message. It removes the context from the discussion below it.