Skip to content

Instantly share code, notes, and snippets.

@lzzy12
Created November 20, 2018 15:29
Show Gist options
  • Save lzzy12/00094caad03d6ff5af0de4bd6af41eb4 to your computer and use it in GitHub Desktop.
Save lzzy12/00094caad03d6ff5af0de4bd6af41eb4 to your computer and use it in GitHub Desktop.
#include <iostream.h>
void main()
{
int num;
cout << "Enter number: ";
cin >> num;
for (int row = 1; row <= num; row++)
{
for (int col = 1; col < 2 * num; col++)
{
if (col < row)
{
cout << col << " ";
}
else if (col > 2 * num - col && col < 2 * num - row)
{
cout << row << " ";
}
else if (col > 2 * num - row)
{
cout << 2 * num - col << " ";
}
else
{
cout << row << " ";
}
}
cout << endl;
}
for (int row = num - 1; row >= 1; row--)
{
for (int col = 2 * num - 1; col >= 1; col--)
{
if (col < row)
{
cout << col << " ";
}
else if (col > 2 * num - col && col < 2 * num - row)
{
cout << row << " ";
}
else if (col > 2 * num - row)
{
cout << 2 * num - col << " ";
}
else
{
cout << row << " ";
}
}
cout << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment