In this tutorial, we will write a C program to print a rectangular star pattern. You may go through the following topic on C first.
Rectangle Star Pattern in C
The program asks for the number of rows and columns that a user wants and prints the result.
#include <stdio.h>
int main()
{
int i, j, rows, col;
printf("Enter number of rows: ");
scanf("%d", &rows);
printf("Enter number of columns: ");
scanf("%d", &col);
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= col; j++)
printf("* ");
printf("\n");
}
return 0;
}
Enter number of rows: 4
Enter number of columns: 7
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *