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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #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
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *