answersLogoWhite

0

#include <stdio.h>

void print_square(int size);

int main()

{

int size;

//promp for size of square

printf("Enter size of square: ");

//read size

scanf("%d", &size);

//print square depending on size

print_square(size);

system("pause");

}

//This function prints a square of starts (size x size)

void print_square(int size)

{

//declare variables

int i,j;

//i is the horizontal row (eg row 1, row 2, row i)

for(i=1; i<=size; i++)

{

//j is the position in the row (eg position 1, position 2, position j)

for(j=1; j<=size; j++)

{

//if the first or last row put a star in the position in the row

if((i==1) (i==size))

{

printf("* ");

}

//for the in between rows

else

{

//put a star on the side positions of the row

if((j==1) (j==size))

{

printf("* ");

}

//put an empty space in the row

else

{

printf(" ");

}

}

}

//print new row in new line

printf("\n");

}

system("pause");

}

User Avatar

Wiki User

13y ago

What else can I help you with?