Write a program with ONLY main function in it that displays a square box with \"
ID: 3546169 • 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
int length;
cin>>length;
for(int i =0;i<lenght;i++)
cout<<'@'<<endl;
\the first edge
\for the side edges
for(int i=0;i<length-2;i++)
{
cout<<'@';
for(int j=0;j<(length-2)*2;j++)
{
cout<<' ';
}
cout<<'@'<<endl;
}
\for the last edge
for(int i =0;i<lenght;i++)
cout<<'@'<<endl;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.