| re: Please help me with these problems.... [homework] Hint for #1
Look where the perfect squares are located. The even ones line up on a diagonal, and the odd one line up on an adjacent diagonal. That way, you can estimate the size of a matrix needed for this calculation. The even and odds do not line up, you should take notice how this affects the starting position (where is 1 in relation to the dimension of the matrix).
Initialize all matrix values to zero. The outer loop should control the direction and conditionally increment the distance you traverse in the matrix, while the inner loop counts the distance travelled and also assigns matrix entries.
After you count all the way up to the number, traverse through the matrix by row, then by column. Print only initialized values, and blank spaces otherwise. Hint for #2
Search this forum, someone was doing a similar problem not that long ago. "Magic Square" is how people usually refer to it.
|