1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
int main()
{
int row;
cout << "Enter the number of rows: ";
cin >> row;
int x = 0;
int count = row;
string line = "";
int length = (row * 2) - 1;
for (int i = 1; i <= row; i++)
{
line = "";
for( int j = 1; j <= i; j++ )
line = " " + to_string(j) + line;
while( line.size() <= length )
line = " " + line;
for( int j = 0; j < line.size(); j++ )
cout << line[j];
for( int j = line.size() - 2; j >= 0; j-- )
cout << line[j];
cout << endl;
}
return 0;
}
| |
does not compensate for numbers > 9. I'll let you figure that out :)
Last edited on