Connecting Tech Pros Worldwide Help | Site Map

Please help me with these problems.... [homework]

Newbie
 
Join Date: Sep 2006
Posts: 2
#1: Sep 9 '06
Hi everybody,
My name's Jack and I'm a newbie in this forum...
Nice to meet you all and i hope i can get along in this forum...
And I also hope that you can help me with my problem...
I'm a very beginner programmer that still learn in C language programming taht I hope I can be an advanced programmer or even expert programmer later :) I have a quiz from my author before and until now I still can't describe how to make this program...

These are the Quiz...

1. Make a program that ask an input from user.
The input is integer number with range 1 - 100
And show the output of the numbers in spiral (rouding) shape

Example:
Input : 9

Output :
5 4 3
6 1 2
7 8 9


Input : 13

Output :
13
5 4 3 12
6 1 2 11
7 8 9 10

2. Make a program that ask an input from user.
The input is an odd number (N)
And show the output in matrix shape from N to N*N
but the numbers must have a same value when it's sum
in horizontally, vertically, and diagonally.

Example:
Input : 3
Output :
8 1 6 = 15
3 5 7
4 9 2

ll
15


I hope i can get your reply soon...
Oh yeah these progrom should be in C language
Thanks before, guys...
Newbie
 
Join Date: Sep 2006
Posts: 2
#2: Sep 9 '06

re: Please help me with these problems.... [homework]


sorry guys for the bad view of output.
In question number 2
the 13 number on the output should be above the 12 number
I hope you can understand...
KUB365's Avatar
Administrator
 
Join Date: Jul 2005
Location: Portland, OR
Posts: 965
#3: Sep 11 '06

re: Please help me with these problems.... [homework]


This is a homework assignment. You have to try it yourself first. When you get stuck, you can then paste your code and we can help debut.
D_C D_C is offline
Needs Regular Fix
 
Join Date: Jun 2006
Posts: 294
#4: Sep 11 '06

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.
Reply