Write a C and Java program to print the Rhombus pattern of stars. A rhombus is a quadrilateral, all of whose sides have the same length.

This post covers the following patterns:

Pattern 1: Rhombus
Pattern 2: Mirror of Rhombus
Pattern 3: Hollow Rhombus
Pattern 4: Mirror of Hollow Rhombus

Pattern 1: Rhombus

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

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

C


Download  Run Code

Java


Download  Run Code

Pattern 2: Mirror of Rhombus

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

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

C


Download  Run Code

Java


Download  Run Code

Pattern 3: Hollow Rhombus

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

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

C


Download  Run Code

Java


Download  Run Code

Pattern 4: Mirror of Hollow Rhombus

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

 
Here the idea remains the same as Pattern 2, but we print ‘*’ only for the last row and first & last cell in each row. Spaces will fill all other positions.

C


Download  Run Code

Java


Download  Run Code

That’s all about printing a rhombus pattern in C and Java.

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