How to print a square using gotoxy in c++?please help? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to print a square using gotoxy in c++?please help?

30th Jan 2018, 6:01 PM
alikhan124
alikhan124 - avatar
2 Answers
+ 20
for(int a=1;a <=n;a++){ for (int b=1;b <=n;b++) System.out.print("*"); System.out.println(""); } //hope u can use it easily ☺ //for hollow square , put condition if ( a==1||b==1||a==n||b==n) print "*" else " "
30th Jan 2018, 6:28 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 2
If you 'still' require a 'gotoxy()' solution : int n; cin>>n; int sx=0,sy=0; // sx = Starting Absicca. // sy = Starting Ordinate. for(int i=0;i<n;i++) { gotoxy( sx, sy+i ); cout<<"*"; gotoxy( sx+i, sy ); cout<<"*"; gotoxy( sx+n, sy+i ); cout<<"*"; gotoxy( sx+i, sy+n ); cout<<"*"; }
30th Jan 2018, 7:50 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar