int main()
{
cout << "Enter a number from 1 to 9: ";
int num;
cin >> num;
bool Plus = true;
for (int j = 0;;)
{
int temp = 0;
bool bTemp = true;
for (int i = (num * 2 - 1); i > 0; --i)
{
int rez = num - temp;
cout << rez << " ";
if (temp < j && bTemp)
++temp;
if (i <= temp + 1)
{
--temp;
bTemp = false;
}
}
if (j == num - 1)
{
Plus = false;
}
if (Plus)
{
++j;
}
else
{
--j;
if (j < 0)
{
cout << endl;
break;
}
}
cout << endl;
}
return 0;
}
Enter a number from 1 to 9: 3
3 3 3 3 3
3 2 2 2 3
3 2 1 2 3
3 2 2 2 3
3 3 3 3 3
#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
cout << "Enter a number from 1 to 9: ";
int num,i0,j0;
cin >> num;
i0 = j0 = num - 1;
for (int i = 0; i < num * 2 - 1; i++)
{
for (int j = 0; j < num * 2 - 1; j++)
cout << 1 + __max(abs(i - i0), abs(j - j0)) << " ";
cout << endl;
}
return 0;
}
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.