- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to print Square inside a Square in C
Program Description
Print Square inside a Square as shown below
Algorithm
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.
Example
/* 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("
"); 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("
"); } getch(); return 0; }
Output
- Related Articles
- C++ Program to Print Square Star Pattern
- Area of a leaf inside a square in C Program?
- Program to print solid and hollow square patterns in C
- Java Program to Print Square Star Pattern
- Golang Program To Print Square Star Pattern
- Swift Program to Print Solid Square Star Pattern
- Swift Program to Print Alphabetic Solid Square Pattern
- Java Program to Print a Square Pattern for given integer
- Print the Non Square Numbers in C
- Area of a leaf inside a square?
- Print maximum sum square sub-matrix of given size in C Program.
- C program to print area of triangle, square, circle, rectangle and polygon using switch case.
- Program for Area Of Square in C++
- 8086 program to find the square root of a perfect square root number
- Matchsticks to Square in C++

Advertisements