# Thread: Listing factors in a grid.

1. ## Listing factors in a grid.

Currently, I'm attempting to output the factors of a number in a grid format as opposed to just a direct line of numbers.

I am trying to use a for loop to accomplish this, however, i'm having a difficult time deducting a formula to create this.

Any input on how to make the output into a grid would be awesome. Thanks.

Code:
```for(i=1;i<=n;i++)
{
if(n%i==0)
cout << n/i <<endl;
}```

2. What do you mean by grid format? How do you want your grid to look?

3. Say n=64

64 32 16 8 4
2 1

64
32
16
8
4
2
1

4. So if you just want a line break after every n numbers, then print a line break after every n numbers. (Use a counter to count how many you've printed on the current line, and when you reach the max print a new line and start over.)

5. Thanks. How many for loops would I need to go about doing that?

6. No special for loops other than the one you've already got that's printing all the numbers.

7. thank you! got it to work using a while statement as a counter, and I replaced the endl; statement in there.