Home  >  Article  >  Backend Development  >  Write a program in C language to print a mirrored hollow parallelogram

Write a program in C language to print a mirrored hollow parallelogram

王林
王林forward
2023-08-30 18:29:081643browse

Program Description

This is a quadrilateral in which two pairs of opposite sides are parallel.

Write a program in C language to print a mirrored hollow parallelogram

There are six important parallelogram properties to know

  • opposite sides are equal (AB = DC).
  • Diagonals are equal (D = B).
  • Adjacent angles are complementary (A D = 180°).
  • If one angle is a right angle, then all angles are right angles.
  • The diagonals of a parallelogram bisect each other.
  • Each diagonal of a parallelogram divides it into two equal parts.

Write a program in C language to print a mirrored hollow parallelogram

Algorithm

  • Accepts the number of rows and columns from the user. Store it in rows and cols variables.
  • To iterate over rows, run an outer loop. The loop structure should be for(r=1; r
  • In order to print spaces, run an inner loop with the loop structure for(c=1; c
  • Print asterisks to form hollow parallelograms and run another inner loop with the loop structure for(c=1; c
  • After printing all the columns of a row, wrap the line, that is, print a new row.

Example

// C program to print mirrored hollow parallelogram
#include <stdio.h>
int main(){
   int rows,cols,r,c;
   clrscr(); /*Clears the Screen*/
   printf("Please enter the number of Rows: ");
   scanf("%d", &rows);
   printf("</p><p>");
   printf("Please enter the number of Columns: ");
   scanf("%d", &cols);
   printf("</p><p>");
   printf("The Mirrored Hollow Parallelogram is: ");
   printf("</p><p>");
   for(r = 1; r <= rows; r++){
      // Display spaces
      for(c = 1; c < r; c++) {
         printf(" ");
      }
      // Display hollow parallelogram
      for(c = 1; c <= cols; c++) {
         if (r == 1 || r == rows || c == 1 || c == cols) {
            printf("*");
         }
         else {
            printf(" ");
         }
      }
      printf("</p><p>");
   }
   getch();
   return 0;
}

Output

Write a program in C language to print a mirrored hollow parallelogram

Write a program in C language to print a mirrored hollow parallelogram

The above is the detailed content of Write a program in C language to print a mirrored hollow parallelogram. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete