Created
October 15, 2025 16:49
-
-
Save juanfal/5a7b2f7d51aad432dfe1e903331e65ef to your computer and use it in GitHub Desktop.
rhombus with numbers
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
// 1.stairofnumbers.cpp | |
// juanfc 2025-10-15 | |
// | |
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
int n = 4; | |
// each growing line | |
for (int width = 1; width <= n; ++width) { | |
// first spaces | |
for (int i = 0; i < n-width; ++i) { | |
cout << ' '; | |
} | |
// then ascending numbers | |
for (int i = 1; i <= width; ++i) { | |
cout << i; | |
} | |
// then descending numbers | |
for (int i = width-1; i > 0; --i) { | |
cout << i; | |
} | |
// ending the line! | |
cout << endl; | |
} | |
// now the shrinking lines | |
for (int width = n-1; width > 0; --width) { | |
// first spaces | |
for (int i = 0; i < n-width; ++i) { | |
cout << ' '; | |
} | |
// then ascending numbers | |
for (int i = 1; i <= width; ++i) { | |
cout << i; | |
} | |
// then descending numbers | |
for (int i = width-1; i > 0; --i) { | |
cout << i; | |
} | |
// ending the line! | |
cout << endl; | |
} | |
return 0; | |
} | |
/* prints: | |
1 | |
121 | |
12321 | |
1234321 | |
12321 | |
121 | |
1 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment