Answer:
C++ code given below with appropriate comments
Step-by-step explanation:
pattern.cpp
#include<iostream>
using namespace std;
void printCross(int n)
{
int i,j,k;
if(n%2) //odd number of lines
{
for(int i=n;i>=1;i--)
{
for(int j=n;j>=1;j--)
j==(n-i+1))
cout<<j;
else
cout<<" ";
cout<<"\\";
}
}
else //even number of lines
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(j==i || j==(n-i+1))
{
cout<<" "<<j<<" ";
}
else
cout<<" ";
}
cout<<"\\";
}
}
}
void printForwardSlash(int n)
{
if(n%2)
{
for(int i=n;i>=1;i--)
{
for(int j=n;j>=1;j--)
{
if(j==n-i+1)
{
cout<<j;
}
else
cout<<" ";
}
cout<<"\\";
}
}
else
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(j==(n-i+1))
{
cout<<j;
}
else
cout<<" ";
}
cout<<"\\";
}
}
}
void printBackwardSlash(int n)
{
if(n%2) // odd number of lines
{
for(int i=n;i>=1;i--)
{
for(int j=n;j>=1;j--)
{
if(j==i)
{
cout<<j;
}
else
cout<<" ";
}
cout<<"\\";
}
}
else //even number of lines
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(j==i)
{
cout<<j;
}
else
cout<<" ";
}
cout<<"\\";
}
}
}
int main()
ch=='B')
printBackwardSlash(num);
else
cout<<"\\Wrong input"<<endl;
return 0;