

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 solid and hollow square patterns in C
Program Description
In geometry, a square is a regular quadrilateral, which means that it has four equal sides and four equal angles.
Solid and Hollow Square will appear as shown below
Algorithm
For Solid Square −
Accept the Number of Rows from the user to draw the Solid Square For each Row, Print * for each Column to draw the Solid Square
For Hollow Square −
Accept the Number of Rows from the user to draw the Hollow Square For the First and Last Row, Print * for each Column For the Remaining Rows, Print * for the first and Last Column.
Example
/* Program to print hollow and Solid Square pattern */ #include <stdio.h> int main(){ int r, c, rows; //Hollow Rhombus int r1,c1, rows1; //Solid Rhombus clrscr(); /* Hollow Square */ printf("Enter the Number of rows for Hollow Square: "); scanf("%d", &rows); printf("\n"); for (r=1; r<=rows; r++){ if (r==1 || r==rows){ for (c=1; c<=rows; c++){ printf("*"); } } else{ for (c=1; c<=rows; c++){ if (c==1 || c==rows){ printf("*"); } else{ printf(" "); } } } printf("\n"); } printf("\n"); /* Solid Square */ printf("Enter the Number of rows for Solid Square: "); scanf("%d", &rows1); printf("\n"); for (r1=1; r1<=rows1; r1++){ for (c1=1; c1<=rows1; c1++){ printf("*"); } printf("\n"); } getch(); return 0; }
Output
- Related Questions & Answers
- Program to print solid and hollow rhombus patterns in C
- C Program to print hollow pyramid and diamond pattern
- Program to print hollow pyramid and diamond pattern in C++
- Program to Print Mirrored Hollow Parallelogram in C
- C program to print hollow rectangle star pattern
- Program to print right and left arrow patterns in C
- Program to print Square inside a Square in C
- Java Program to Print Hollow Right Triangle Star Pattern
- How to make hollow square marks with Matplotlib in Python?
- Java Program to Print Square Star Pattern
- Print the Non Square Numbers in C
- C program to print area of triangle, square, circle, rectangle and polygon using switch case.
- Print all n digit patterns formed by mobile Keypad in C++
- Print maximum sum square sub-matrix of given size in C Program.
- Program for triangular patterns of alphabets in C
Advertisements