5
4 5 4
3 4 5 4 3
2 3 4 5 4 3 2
1 2 3 4 5 4 3 2 1
2 3 4 5 4 3 2
3 4 5 4 3
4 5 4
5
#include <iostream>
using namespace std;
int main()
{
int n=5;
for (int i = 0; i < 5; i++)
{
for (int j = n - i; j <= n; j++)
{
cout << j << " ";
}
for (int j = n-1; j >= n-i; j--)
{
cout << j << " ";
}
cout << endl;
}
for (int i = 0; i < 4; i++)
{
for (int j = i+2; j <= n; j++)
{
cout << j << " ";
}
for (int j = n -1; j >=2+i; j--)
{
cout << j << " ";
}
cout << endl;
}
}
Comments
Leave a comment