Question: This program is supposed to make a NxN box when you type in a number N into the program. The right side of the box

This program is supposed to make a NxN box when you type in a number N into the program. The right side of the box is always messed up. Can anyone help me find out the solution to this? Included is my code and a picture of when it is compiled

.This program is supposed to make a NxN box when you type

in a number N into the program. The right side of the

As you can see the right side is always messed up, it should be a normal box.

code:

#include

int main()

{

int n,i,j;

printf("enter the value of n ");

scanf("%d",&n); // reading the n value

for (i=0;i//loop iteration

{

if (i==0 || i==n-1) //checking first and last line

{

for (j=0;j

printf("* "); //printing all stars in first and last line

}

else

{

printf("* "); // apart from first and last line printing first *

for(j=2;j

printf(" "); // printing remaining spaces

printf("* "); // printing last star

}

printf(" "); //printing new line

}

return 0;

}

* k

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!