Загрузка данных


#include <iostream>
#include <iomanip>
using namespace std;

const int STROKI = 3;
const int STOLBCY = 4;

// считаем, сколько символов занимает число (минус тоже считается)
int kolSimvolov(int chislo)
{
    int kol = 0;

    if (chislo <= 0)
    {
        kol = 1;
    }

    while (chislo != 0)
    {
        chislo = chislo / 10;
        kol++;
    }

    return kol;
}

// рисуем горизонтальную линию +-----+-----+
void liniya(int shirina)
{
    int stolbec, i;

    for (stolbec = 0; stolbec < STOLBCY; stolbec++)
    {
        cout << "+";
        for (i = 0; i < shirina + 2; i++)
        {
            cout << "-";
        }
    }
    cout << "+" << endl;
}

void pipicka(int masiv[STROKI][STOLBCY])
{
    int stroka, stolbec;
    int shirina = 1;

    // ищем самое длинное число в массиве
    for (stroka = 0; stroka < STROKI; stroka++)
    {
        for (stolbec = 0; stolbec < STOLBCY; stolbec++)
        {
            if (kolSimvolov(masiv[stroka][stolbec]) > shirina)
            {
                shirina = kolSimvolov(masiv[stroka][stolbec]);
            }
        }
    }

    // выводим таблицу
    liniya(shirina);

    for (stroka = 0; stroka < STROKI; stroka++)
    {
        cout << "|";
        for (stolbec = 0; stolbec < STOLBCY; stolbec++)
        {
            cout << " " << setw(shirina) << masiv[stroka][stolbec] << " |";
        }
        cout << endl;
        liniya(shirina);
    }
}

int main()
{
    int masiv[STROKI][STOLBCY] = {
        {1, 2, 3, 4},
        {10, -5, 100, 7},
        {8, 9, 0, 11}
    };

    pipicka(masiv);
}