Actaully, a Single nested loop would work fine:
Code:
void drawSquare(int s, char c) {
for( int i = 0; i < s; i++ ) {
for( int j = 0; j < s; j++ ) {
if( (i == 0 || i == s-1) || (j == 0 || j == s-1) )
printf("%c",c);
else
printf(" ");
}
printf("\n");
}
}
// use me like this in main program:
drawSquare( 5, 'R');
:P
P.S: FIgured I'd put SOME explination to the code
basicly the nested loop gives you the sqaure traversal row by column.
Code:
i == 0
// this accounts for any and all cases where we are in the top row of the square
i == s-1
// this accounts for any and all cases where we are in the bottom row of the sqaure
j == 0
// this accounts for any and all cases where ew are in the left most column of the square
j == s-1
// this accounts for any and all cases where we are in the right most column of the square
// any other situation we are inside the actualy sqaure boundry, so we draw a space.