कार्यक्रम विवरण
स्क्वायर के अंदर स्क्वायर प्रिंट करें जैसा कि नीचे दिखाया गया है
एल्गोरिदम
Accept the number of rows the outer Square to be drawn Display the Outer Square with the number of rows specified by the User. Display another square inside the outer square.
उदाहरण
/* Program to print Square inside Square */ #include <stdio.h> int main() { int r, c, rows; clrscr(); printf("Enter the Number of rows to draw Square inside a Square: "); scanf("%d", &rows); printf("\n"); for (r = 1; r <= rows; r++){ for (c = 1; c <= rows; c++){ if ((r == 1 || r == rows || c == 1 || c == rows) || (r >= 3 && r <= rows - 2 && c >= 3 && c <= rows - 2) && (r == 3 || r == rows - 2 || c == 3 || c == rows - 2)){ printf("#"); } else{ printf(" "); } } printf("\n"); } getch(); return 0; }
आउटपुट