on
CSS
- Get link
- X
- Other Apps
#include
<stdio.h>
standard input/output library for function printf() and scanf()
Main
Function Start
int main() {
Start of the main function where the execution begin
Variable
Declarations
int i, j;
int n = 7;
i and j are loop control variable
n = 7
specifies the size of the pattern: it will be 7 rows × 7 column.
for (i = 0;
i < n; i++) {
This loop control the row number (from 0 to 6).
Run exactly 7 times because n = 7.
Inner Loop
for (j = 0; j < n; j++) {
loop control the column number within each row.
if (j == 0
||
(i == 0 && j < n - 1) ||
(i == n - 1 && j < n - 1) ||
(j == n - 1 && i != 0 && i
!= n - 1))
printf("*");
else
printf(" ");
else
printf(" ");
If none of
the above conditions are true, print a space.
printf("\n");
printing all columns of a row, a new line is printed.
return 0;
Comments
Post a Comment