Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void vop(int **arr,int row, int cols)/*Функция создания и заполнения массива*/
- {
- for (int i = 0; i < row; i++)
- {
- for (int j = 0; j < cols; j++)
- {
- cout << "Введите " << j + 1 << " элемент " << i + 1 << " строки: ";
- cin >> arr[i][j];
- }
- cout << endl;
- }
- cout << endl;
- for (int i = 0; i < row; i++)
- {
- for (int j = 0; j < cols; j++)
- {
- cout << arr[i][j] << " ";
- }
- cout << endl;
- }
- }
- int main()
- {
- setlocale(LC_ALL, "rus");
- int row;
- int cols;
- cout << "===========Первая матрица=============" << endl;
- cout << "Введите количество строк: ";
- cin >> row;
- cout << endl;
- cout << "Введите колочесиво столбцов: ";
- cin >> cols;
- cout << endl;
- int** arr = new int* [row];
- for (int i = 0; i < row; i++)
- {
- arr[i] = new int[cols];
- }
- vop(arr, row, cols);
- /*================================================================================================================*/
- int row1;
- int cols1;
- cout << "===========Вторая матрица=============" << endl;
- cout << "Введите количество строк: ";
- cin >> row1;
- cout << endl;
- cout << "Введите колочесиво столбцов: ";
- cin >> cols1;
- cout << endl;
- int** arr1 = new int* [row1];
- for (int i = 0; i < row1; i++)
- {
- arr1[i] = new int[cols1];
- }
- vop(arr1, row1, cols1);
- /*================================================================================================================*/
- int sum = 0;
- int el = 0;
- int row2;
- int cols2;
- row2 = row;
- cols2 = cols1;
- int** arr2 = new int* [row2];
- for (int i = 0; i < row2; i++)
- {
- arr2[i] = new int[cols2];
- }
- if (cols = row1)
- {
- for (int k = 0; k < row; k++)
- {
- for (int i = 0; i < cols1; i++)
- {
- for (int j = 0; j < cols; j++)
- {
- el = arr[k][j] * arr1[j][i];
- sum += el;
- }
- arr2[k][i] = sum;
- sum = 0;
- }
- }
- /*================================================================================================================*/
- cout << "===========Сумма матриц===================" << endl;
- cout << endl;
- for (int i = 0; i < row; i++)
- {
- for (int j = 0; j < cols1; j++)
- {
- cout << arr2[i][j] << " ";
- }
- cout << endl;
- }
- }
- else
- {
- cout << "Количество стобцов в первой матрице должно быть равно количеству строк во второй!" << endl;
- }
- /*Удаление массивов*/
- for (int i = 0; i < row; i++)
- {
- delete[] arr[i];
- }
- for (int i = 0; i < row1; i++)
- {
- delete[] arr1[i];
- }
- for (int i = 0; i < row; i++)
- {
- delete[] arr2[i];
- }
- delete[] arr;
- delete[] arr1;
- delete[] arr2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement