Signup/Sign In

C program to print Hollow Rhombus Star Pattern

learn C language

A rhombus is a quadrilateral, which is a two-dimensional figure having four sides joined together. The opposite sides of a rhombus are parallel to one other, which is one of its properties.

In nature, all of the sides of a rhombus are equal. In nature, the opposite angles of a rhombus are also equal. The diagonals of a rhombus also cut each other at right angles as a result of these properties.

Algorithm For Hollow Rhombus:

  • Get the input from the user for the number of rows in the hollow rhombus.
  • Based on the input print the first row contains the number of stars or symbols.
  • Only the First and Last star should be printed and leave the spaces between the first and last star
  • Continue the same until you reach the final row.
  • Just like step 2 print the number of stars based on the given number of rows.

Logic To Print The Hollow Rhombus:

  • Get the input from the user to print a number of rows, and store it in a variable.
  • Define the outer loop using structure for(i= 2; I<=rows; i++)
  • To print the spaces, the inner loop should be created from 1 to rows -i.
  • Define the inner loop using structure for(j= 1; j<=rows -i; j++).
  • To print the stars another loop should be created from 1 to rows.
  • Define the another loop using structure for(j= 1; j<=rows; j++).
  • Print the star in the first and last row, leaving spaces between the stars.
  • Stars should be printed only when the condition meets i==1; or i == rows;
  • After printing stars in rows and columns, print a new line.

C Program To Print The Hollow Rhombus:

#include <conio.h>
#include<stdio.h>
int main()
{
    int i,j,n;
    char ch;
 
    printf("Enter The Number Of Rows To Print The Hollow Rhombus Pattern: ");
    scanf("%d%c",&n,&ch);
    printf("Enter The Symbol To Represent Hollow Rhombus: ");
    ch=getchar();
 
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n-i;j++)
        {
            printf(" ");
        }
	    
		if(i==1 || i==n)
            for(j=1;j<=n;j++)
            {
                printf("%c",ch);
            }
        else
	    {
            for(j=1;j<=n;j++)
            {  
                if(j==1 || j==n)
                    printf("%c",ch);
                else
                    printf(" ");
            }
        }
        printf("\n");
                       
    }             
 
 
    return 0;
}

Output:

Hollow rhombus