HELP

[1] Write a program 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. (side>2)
For example, if side is 4, the program displays
@@@@
@ @
@ @
@@@@

[2] Write a program that displays n depth * pyramid.

For example,Input: 4
Output:
*
***
*****
*******
show what code you done so far?
and don't hope people to write the code for u
SO this is what I have so far. But I am having problem making a square.

#include <iostream>
using namespace std;


int main()
{
int side;

cout<<"Enter the Side: ";
cin>>side;

for (int i=1;i<=side;i++)
{ cout<<"@"<<endl;


for (int j=0;j<side;j++)
cout<<"@"<<endl;

}

cout<<endl;
}

Think about what that square looks like. Take a simple 4x4 square: (ignore the fact that this font makes it rectangular)
@@@@
@  @
@  @
@@@@
There's one line of 4 @ symbols, 2 lines of an @ symbol, 2 spaces, and an @ symbol, and then another line of 4 @ symbols.

Then look at a 5x5:
@@@@@
@   @
@   @
@   @
@@@@@
There's one line of 5 @ symbols, 3 lines of an @ symbol, 3 spaces, and an @ symbol, and then another line of 5 @ symbols.

See the pattern?
Last edited on
Topic archived. No new replies allowed.