печать формы числовым

int number1=5;
int number2=4;
for(int i=1; i<=7; i++)
{
if(rows <= 1)
for(int i=1; i<=7; i++)
{
cout<< number1;
}
else if(i<7)
{
cout<< endl;
for(int j=1; j<=6; j++)
{
if(side2==1 || side2==6)
cout<< number1;
else
cout<< " ";
}
}
else
{
cout<< endl;
for(int k=1; k<=6; k++)
{
cout<<number1;
}
}

Моя программа печатает эту форму

 555555555
5       5
5       5
5       5
5       5
555555555

но я пытался сделать так, чтобы это выглядело так

 555555555
544444445
543333345
543222345
543212345
543222345
543333345
544444445
555555555

Я слышал об этом сайте от друга, насколько вы полезны, ребята, я бы хотел, чтобы вы тоже мне помогли.

-2

Решение

Самый простой будет:

std::cout << "555555555" << std::endl;
std::cout << "544444445" << std::endl;
std::cout << "543333345" << std::endl;
std::cout << "543222345" << std::endl;
std::cout << "543212345" << std::endl;
std::cout << "543222345" << std::endl;
std::cout << "543333345" << std::endl;
std::cout << "544444445" << std::endl;
std::cout << "555555555" << std::endl;

и с петлей:

for (int y = 0; y < 9; ++y) {
for (int x = 0; x < 9; ++x) {
std::cout << char('1' + std::max(std::abs(x - 4), std::abs(y - 4)));
}
std::cout << std::endl;
}
0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector