Created
November 20, 2018 15:29
-
-
Save lzzy12/00094caad03d6ff5af0de4bd6af41eb4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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