String pattern printing challenge
Prefer Clear Naming over using namespace std

According to the [MSDN website]:


  Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries.


A collision is when 2 different functions have the same name, the same arguement types and a
similar functionallity (this is why they have the same name). Someone developing software may want
to override a function such as std::cout, std::cin or they may want to override the functionallity
of a class such as std::vector or std::stack. Namespaces allow these constructs to be overriden.

The use of the programming statement:

using namespace std;


hides the fact that cin, cout, vector and stack are coming from the namespace std where cin, cout,
vector and stack are used in the code. This can cause confusion of where the code is actually
coming from.

As the software becomes more complex and uses more libraries this becomes a bigger problem.

For a more detailed discussion of why it is a bad idea to use using namespace std;
see this stackoverflow question and this stackoverflow question.

The Use of new is Preferred Over malloc in C++
The code contains the line:

    int *arr = (int*)malloc(n * sizeof(int));


This is a C programming language construct. In C++ it is much more accepted to use

    int *a = new int[n];


Even this is out dataed because of all the container classes, and generally using pointers is
frowned upon in C++ because it is error prone.

Declare Variables When Needed
In the older versions of the C programming language one had to put the variable declarations at
the top. The current versions of C and C++ allow variables to be declared as needed.

An example of this is to move the variable toggle to be within the for loop.

Limit the Use of std::endl
It would be better to use '\n' to insert the new lines in the loops because std::endl does a file flush
each time it is called. This makes it an expensive operation.

Use Boolean Variables
In the C programming language there is no bool variable type unless one includes stdbool.h. In the
C++ programming language it would be better to implement the variable toggle as a bool variable
rather than as an int. Then you can use true and false rather than 1 and 0 respectively.