C program to print rhombus pattern

Write a C program to print Rhombus pattern of stars. A rhombus is a quadrilateral all of whose sides have the same length. This post covers below patterns –

 

 


 

Pattern 1: Rhombus


             *  *  *  *  *
          *  *  *  *  *
       *  *  *  *  *
    *  *  *  *  *
 *  *  *  *  *

We can have n rows. Here, 1st row will contain (n-1) spaces followed by n star, 2nd row will contain (n-2) spaces followed by n stars, and so on.. We can use nested loops to print this pattern where outer loop represents row number (say i) and inner loop prints the space (n-i times) followed by the star pattern (n times).

C

Download   Run Code

Pattern 2: Mirror of Rhombus


 *  *  *  *  *
    *  *  *  *  *
       *  *  *  *  *
          *  *  *  *  *
             *  *  *  *  *

Suppose we have n rows. 1st row will contain 0 space followed by n stars, 2nd row will contain 1 space followed by n stars, 3rd row will contain 2 spaces followed by n stars and so on.. We can use nested loops to print this pattern where outer loop represents row number (say i) and inner loop prints the space (i-1 times) followed by the star pattern (n times).

C

Download   Run Code

Pattern 3: Hollow Rhombus


             *  *  *  *  *
          *           *
       *           *
    *           *
 *  *  *  *  *

The idea remains same as Pattern 1 but here we print ‘*’ only for last row and first & last positions for each row. For all other positions, we print space.

C

Download   Run Code

Pattern 4: Mirror of Hollow Rhombus


 *  *  *  *  *
    *           *
       *           *
          *           *
             *  *  *  *  *

Here the idea remains the same as Pattern 2 but we print ‘*’ only for last row and first & last cell in each row. All other positions will be filled by spaces.

C

Download   Run Code

 
Exercise: Extend the solution to print parallelogram (quadrilateral with two pairs of parallel sides).

 
Thanks for reading.




Please use ideone or C++ Shell or any other online compiler link to post code in comments.
Like us? Please spread the word and help us grow. Happy coding 🙂
 





Leave a Reply

Notify of
avatar
wpDiscuz