+ 2
How to code rectangle inside the given rectangle in c
********** * * * * * * * * ********** I tried this code #include <stdio.h> int main() { int a=10, b=6; for(int i=1; i<=b; i++) { for(int j=1; j<=a; j++) { if(i==1||i==6||j==1||j==10) printf("*"); else{ printf(" "); } } printf("\n"); } return 0; }
10 Answers
+ 6
Alfred Monir Hugo this is one way.
https://code.sololearn.com/cw063aRXj6Mo/?ref=app
+ 4
If you want to use the same approach, use more conditions using i and j to draw the inner rectangle.
+ 4
Alfred Monir Hugo no problem. I gave the answer because you showed your initial code and made an attempt asking reasonable questions. Sometimes people ask for answers without making any attempt. For these questions, we're discouraged from showing a solution immediately. Hope you can take it from here for similar problems.
+ 3
BTW if what you have drawn is the outer rectangle, you don't have enough 'rows' to have a border between the two rectangles and to also have any vertical space inside the inner one.
+ 3
You don't have to.
+ 3
If you are using console output, it is not possible to draw one rectangle first and then the other one because there is no easy way to reposition the cursor.
+ 2
Sonic ok I am trying on that but output is getting different
+ 2
Sonic yes it is the outer rectangle, so should we draw inner rectangle first?
+ 2
Sonic then what is the correct way to get the output
+ 1
Sonic Thank you for the answer