We draw a rectangular frame of n \times m as follows:
In the first row, we output asterisks;
We output n - 2 rows. In each row, we output an asterisk, m - 2 spaces, and another asterisk, but only if m > 1;
In the last -th row, we output asterisks, but only if n > 1.
Algorithm Implementation
Read the input values and .
scanf("%d %d", &n, &m);Output the first row – asterisks.
for (i = 0; i < m; i++)
printf("*");
printf("\n");Output n - 2 rows. In each row, output an asterisk, m - 2 spaces, and another asterisk, but only if m > 1.
for (i = 0; i < n - 2; i++)
{
printf("*");
for (j = 0; j < m - 2; j++)
printf(" ");
if (m > 1)
printf("*");
printf("\n");
}Output the last row – asterisks. Output it only if n > 1.
if (n > 1)
{
for (i = 0; i < m; i++)
printf("*");
printf("\n");
}