Home > Backend Development > C++ > Program to print solid and hollow square patterns in C language

Program to print solid and hollow square patterns in C language

PHPz
Release: 2023-09-03 13:37:04
forward
1629 people have browsed it

Program Description

In geometry, a square is a regular quadrilateral, meaning it has four equal sides and four equal angles.

The solid and hollow squares will look like this

Program to print solid and hollow square patterns in C language

Algorithm

For solid squares-

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
Copy after login

For a 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.
Copy after login

Example

the Chinese translation is:

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("</p><p>");
   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("</p><p>");
   }
   printf("</p><p>");
   /* Solid Square */
   printf("Enter the Number of rows for Solid Square: ");
   scanf("%d", &rows1);
   printf("</p><p>");
   for (r1=1; r1<=rows1; r1++){
      for (c1=1; c1<=rows1; c1++){
         printf("*");
      }
      printf("</p><p>");
   }
   getch();
   return 0;
}
Copy after login

Output

Program to print solid and hollow square patterns in C language

The above is the detailed content of Program to print solid and hollow square patterns in C language. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template