+ 6
Can this program be improved to print a hollow square?
I mean, can we improve the looping? https://code.sololearn.com/cJKUZr7XwDXo/?ref=app
8 Respostas
+ 22
No need to put character in an array, just use 2 loop, and inside those 2 loops, use Conditionals.
Link to lesson:
https://www.sololearn.com/learn/C/2923/?ref=app
//use OR (||) between conditions as any of these conditions need to be true for placing star
+ 20
● run 2 loops from 0 to n, and think it like a matrix in which you can use condition to put "*" for rowNumber=0, rowNumber=n, columnNumber=0, columnNumber=n else print a space " "
● moving to next line in each iteration of outer loop using "\n"
+ 10
Gaurav Agrawal I had thought of it, but how do I put a character in an array? Should I use 'putchar' ? If yes, how?
+ 9
YUGABDH PASHTE I mean, to print a solid square, we use a single nested loop like this.....
https://code.sololearn.com/cV8mgnszagkm/?ref=app
Can we use a similar loop for a hollow square?
+ 3
https://code.sololearn.com/cj24jL6h3etd/?ref=app
Try this one you have to give len of side of square
+ 1
Isn't it's like your code already doing it? What else you want to do with it?
0
What is "return 0" used for? Code runs even without it.
0
It returns 0 to calling function
As in my code I have return type as void so it's working even if you don't write return 0. When you have return type as int u suppose to write return 0
As calling function expecting int as return value.