I am grinding away at a simple for-loop exercise where the user can enter a width and a height, and the program prints out a square with stars and spaces, like this:
Enter width and height: 8 4
********
* *
* *
********
and I have made a solution, but it just feels like I could redsuce the number of blocks with loops some... Can somebody help me with this? Here is the code:
#include <stdio.h>
int main(void)
{
int width, height;
printf("Enter width and height: ");
scanf("%d %d", &width, &height);
for(int i = 0; i < 1; i++)
{
for (int j = 0; j < width; j++)
{
printf("*");
}
printf("\n");
}
for(int i = 0; i < height - 2; i++)
{
printf("*");
for (int j = 0; j < width -2; j++)
{
printf(" ");
}
printf("*\n");
}
for(int i = 0; i < 1; i++)
{
for (int j = 0; j < width; j++)
{
printf("*");
}
printf("\n");
}
}
Thank you in advance!