Write a program with ONLY main function in it that displays a square box with \"
ID: 3546168 • Letter: W
Question
Write a program with ONLY main function in it that displays a square box with "@" whose side is specified by a variable "side". The value of "side" will be input from the user of your program. For loop is required in this program.
for example,
If side is 4, the program displays
@@@@
@ @
@ @
@@@@
2. Try to move the appropriate coding into a function called "Display" and try to call the function from main to get the same result as problem 1.
3. Try to use both problem 1 and problem 2 to draw the following,
@@@@
@ @
@ @
@@@@
@@@@
@ @
@ @
@@@@
Hint : Think about calling the function defined in problem 2.
Explanation / Answer
please rate - thanks
if you don't normally use #include <conio.h> and getch()
just remove them
#include <stdio.h>
#include <conio.h>
int main()
{int i,j,n;
printf("Enter size of square: ");
scanf("%d",&n);
for(i=0;i<n;i++)
printf("@");
printf(" ");
for(i=0;i<n-2;i++)
{printf("@");
for(j=0;j<n-2;j++)
printf(" ");
printf("@ ");
}
for(i=0;i<n;i++)
printf("@");
printf(" ");
getch();
return 0;
}
-------------------------------------------
#include <stdio.h>
#include <conio.h>
void square(int );
int main()
{int i,j,n;
printf("Enter size of square: ");
scanf("%d",&n);
square(n);
getch();
return 0;
}
void square(int n)
{int i,j;
for(i=0;i<n;i++)
printf("@");
printf(" ");
for(i=0;i<n-2;i++)
{printf("@");
for(j=0;j<n-2;j++)
printf(" ");
printf("@ ");
}
for(i=0;i<n;i++)
printf("@");
printf(" ");
}
--------------------
#include <stdio.h>
#include <conio.h>
void square(int );
int main()
{int i,j,n;
printf("Enter size of square: ");
scanf("%d",&n);
square(n);
square(n);
getch();
return 0;
}
void square(int n)
{int i,j;
for(i=0;i<n;i++)
printf("@");
printf(" ");
for(i=0;i<n-2;i++)
{printf("@");
for(j=0;j<n-2;j++)
printf(" ");
printf("@ ");
}
for(i=0;i<n;i++)
printf("@");
printf(" ");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.