# C Programming Q?

This is a discussion on C Programming Q? within the C Programming forums, part of the General Programming Boards category; I need to write a program which prints a square (made out of asterisks) of a certain size, something like ...

1. ## C Programming Q?

I need to write a program which prints a square (made out of asterisks) of a certain size, something like printing squares of size 1 to 10.

"open'' squares, like this:

****
* *
* *
****
instead of filled squares. as open boxes of 1 & 2 are not possible...im supposed to start from 3.

PS- ive just started learning C...id prefer simple approach and codes. the length is not a problem.

2. FYI the box is suposed to be with the asterixs n not with these - ,
*****
*----*
*----*
*----*
*****

3. Post the code for what u r waitin dude

4. Well, given a number n in the range 1,10, the dimensions are (obviously) n*n. The first line you print has n "*"s, the last line you print has n "*"s, and every line in between has (n-2) " "s (spaces) surrounded by 2 "*s". There are (n-2) lines in between the first and last lines (lines with only "*"s). For example, n =3:
Code:
```***  // 3 "*"s
* *  // 3-2 = 1 lines with 3-2=1 spaces, surrounded by 1 "*" on either side
***  // 3 "*"s```
Hopefully the solution is obvious. Give it an attempt, and post your code along with any errors/questions, when any arise.

5. Well given a N size square. The first and last rows have N asterisks, with the rows in between having one asterisk, followed by N-2 spaces, followed by an asterisk.

There really isn't much to it.

6. Creepy! :P

7. Try to write some code or pusdo code dude than your learning will be faster

Code:
```input
loop 0 to input - 1
if 0 or input - 1
loop 0 to input - 1 print *
else
print *
loop 1 to input - 2 print ' '
print *```

8. Originally Posted by RockyMarrone
Try to write some code or pusdo code dude than your learning will be faster

Code:
```input
loop 0 to input - 1
if 0 or input - 1
loop 0 to input - 1 print *
else
print *
loop 1 to input - 2 print ' '
print *```
I wouldn't do it that way, just loop from N+1 to N-1 and avoid the "if-else" rubbish.