Программа считает произведение двух матриц. Первые две матрицы есть, а конечной нет. В чем может быть ошибка?

#include iostream>
#include stdlib.h>

int main()
{
    system("color 70");
    setlocale(LC_ALL, "ru");
    srand(time(NULL));
    int m, n,k;
    std::cout << "Введите кол-во строк M 1-й матрицы:  ";
    std::cin >> m;
    std::cout << "Введите кол-во столбцов K 1-й матрицы: ";
    std::cin >> k;
    std::cout << "Введите кол-во столбцов N 2-й матрицы:  ";
    std::cin >> n;
    std::cout << "Кол-во столбцов K 1-й матрицы = кол-ву строк K 2-й матрицы." << std::endl;
    int** arrayA;
    arrayA = (int**)malloc(m * sizeof(int*));
    int** arrayB;
    arrayB = (int**)malloc(k * sizeof(int*));
    int** arrayC;
    arrayC = (int**)malloc(n * sizeof(int*));

    for (int i = 0; i < m; i++)
    {
        arrayA[i] = (int*)malloc(k * sizeof(int));
        for (int j = 0; j < k; j++)
        {
            arrayA[i][j] = rand() % 10;
        }
    }
    for (int i = 0; i < k; i++)
    {
        arrayB[i] = (int*)malloc(n * sizeof(int));
        for (int j = 0; j < n; j++)
        {
            arrayB[i][j] = rand() % 10;
        }
    }
    std::cout << "Исходные массивы: " << std::endl;
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < k; j++)
        {
            std::cout << arrayA[i][j] << "  ";
        }
        std::cout << std::endl;
    }
    std::cout << "\n\n";
    for (int i = 0; i < k; i++)
    {
        for (int j = 0; j < n; j++)
        {
            std::cout << arrayB[i][j] << "  ";
        }
        std::cout << std::endl;
    }

    for (int i = 0; i < m; ++i)
    {
        arrayC[i] = (int*)malloc(n * sizeof(int));
        for (int j = 0; j < n; ++j)
        {
            arrayC[i * n + j] = 0;
            for (int f = 0; f < k; ++f)
                arrayC[i * n + j] += *(arrayA[i * k + f]) * *(arrayB[k * n + j]);
        }
    }

    std::cout << "\n\n\nПроизведение матриц: " << std::endl;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            std::cout << arrayC[i][j] << "  ";
        }
        std::cout << std::endl;
    }

    for (int i = 0; i < m; i++)
        free(arrayA[i]);
    for (int i = 0; i < k; i++)
        free(arrayB[i]);
    for (int i = 0; i < m; i++)
        free(arrayC[i]);
    free(arrayA);
    free(arrayB);
    arrayA = 0;
    arrayB = 0;
    arrayC = 0;
    system("pause");
    return 0;
}

Ответы (0 шт):