# Program to print solid and hollow rectangle star pattern | faceprep

Program to print solid and hollow rectangle star pattern is discussed here. Given the number of rows and columns, print the solid and hollow rectangle star patterns.

##### Solid rectangular star pattern:

Number of rows: 3
Number of columns: 5

## Program to print solid rectangular star pattern

/* C program to print solid rectangle star pattern */
#include <stdio.h>

/* Function to print solid rectangle*/
void solid_rectangle(int n, int m)
{
int i, j;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= m; j++)
{
printf(“*”);
}
printf(“\n”);
}

}

int main()
{
int rows, columns;
printf(“\nEnter the number of rows : “);
scanf(“%d”, &rows);
printf(“\nEnter the number of columns : “);
scanf(“%d”, &columns);
printf(“\n”);
solid_rectangle(rows, columns);
return 0;
}

/* C++ program to print solid rectangle star pattern */
#include <iostream>
using namespace std;

/* Function to print solid rectangle*/
void solid_rectangle(int n, int m)
{
int i, j;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= m; j++)
{
cout << “*”;
}
cout << endl;
}
}

int main()
{
int rows, columns;
cout << “\nEnter the number of rows : “;
cin >> rows;
cout << “\nEnter the number of columns : “;
cin >> columns;
cout << endl;
solid_rectangle(rows, columns);
return 0;
}

/* Java program to print solid rectangle star pattern */
import java.util.*;
public class Main
{
/* Function to print solid rectangle*/
static void solid_rectangle(int n, int m)
{
int i, j;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= m; j++)
{
System.out.print(“*”);

}
System.out.print(“\n”);
}

}

public static void main (String args[])
{
int rows, columns;
Scanner sc = new Scanner(System.in);
System.out.print(“\nEnter the number of rows : “);
rows = sc.nextInt();
System.out.print(“\nEnter the number of columns : “);
columns = sc.nextInt();
System.out.print(“\n”);
solid_rectangle(rows, columns);
}
}

# Python program to print solid rectangle star pattern

# Function to print solid rectangle
def solid_rectangle(n, m):
for i in range(1, n+1):
for j in range(1, m+1):
print(“*”, end = “”)
print()

rows = int(input(“Enter the number of rows : “))
columns = int(input(“Enter the number of columns : “))
solid_rectangle(rows, columns)

Output:

##### Hollow rectangular star pattern:

Number of rows: 3
Number of columns: 5

## Program to print hollow rectangle star pattern

/* C program to print hollow rectangle star pattern */
#include <stdio.h>

/* Function to print hollow rectangle*/
void hollow_rectangle(int n, int m)
{
int i, j;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= m; j++)
{
if (i==1 || i==n || j==1 || j==m)
printf(“*”);
else
printf(” “);
}
printf(“\n”);
}

}

int main()
{
int rows, columns;
printf(“\nEnter the number of rows : “);
scanf(“%d”, &rows);
printf(“\nEnter the number of columns : “);
scanf(“%d”, &columns);
printf(“\n”);
hollow_rectangle(rows, columns);
return 0;
}

/* C++ program to print hollow rectangle star pattern */
#include <iostream>
using namespace std;

/* Function to print hollow rectangle*/
void hollow_rectangle(int n, int m)
{
int i, j;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= m; j++)
{
if (i==1 || i==n || j==1 || j==m)
cout << “*”;
else
cout << ” “;
}
cout << endl;
}
}

int main()
{
int rows, columns;
cout << “\nEnter the number of rows : “;
cin >> rows;
cout << “\nEnter the number of columns : “;
cin >> columns;
cout << endl;
hollow_rectangle(rows, columns);
return 0;
}

/* Java program to print hollow rectangle star pattern */
import java.util.*;
public class Main
{
/* Function to print hollow rectangle*/
static void hollow_rectangle(int n, int m)
{
int i, j;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= m; j++)
{
if (i==1 || i==n || j==1 || j==m)
System.out.print(“*”);
else
System.out.print(” “);
}
System.out.print(“\n”);
}

}

public static void main (String args[])
{
int rows, columns;
Scanner sc = new Scanner(System.in);
System.out.print(“\nEnter the number of rows : “);
rows = sc.nextInt();
System.out.print(“\nEnter the number of columns : “);
columns = sc.nextInt();
System.out.print(“\n”);
hollow_rectangle(rows, columns);
}
}

# Python program to print hollow rectangle star pattern

# Function to print hollow rectangle
def hollow_rectangle(n, m):
for i in range(1, n+1):
for j in range(1, m+1):
if(i == 1 or i == n or j == 1 or j == m):
print(“*”, end = “”)
else:
print(” “, end = “”)
print()

rows = int(input(“Enter the number of rows : “))
columns = int(input(“Enter the number of columns : “))
hollow_rectangle(rows, columns)

Output: