Даны 2 целочисленные матрицы размером n * m. Написать программу, которая формирует двумерный массив по следующему правилу: нечетные строки массива 1 и четные строки массива 2. Две матрицы создал , а дальше хз! Хелпаните пж. #include<iostream> #include "windows.h" using namespace std; int main() { SetConsoleCP(1251); SetConsoleOutputCP(1251); int i,j,n, m, Matr[10][10], Matr2[10][10]; cout << "Введіть кількість рядків:"; cin >> n; cout << "Введіть кількість стовбців:" ; cin >> m; cout << "Введіть значення матриці 1:"; for (i = 0; i < n; i++) for (j = 0; j < m; j++) cin >> Matr[i][j]; cout << "Matr \n"; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) cout << Matr[i][j] << "\t"; cout << endl; } cout << "Введіть значення матриці 2:"; for (i = 0; i < n; i++) for (j = 0; j < m; j++) cin >> Matr2[i][j]; cout << "Matr2 \n"; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) cout << Matr2[i][j] << "\t"; cout << endl; } system("pause"); return 0; } Код #include<iostream> #include "windows.h" using namespace std; int main() { SetConsoleCP(1251); SetConsoleOutputCP(1251); int i,j,n, m, Matr[10][10], Matr2[10][10]; cout << "Введіть кількість рядків:"; cin >> n; cout << "Введіть кількість стовбців:" ; cin >> m; cout << "Введіть значення матриці 1:"; for (i = 0; i < n; i++) for (j = 0; j < m; j++) cin >> Matr[i][j]; cout << "Matr \n"; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) cout << Matr[i][j] << "\t"; cout << endl; } cout << "Введіть значення матриці 2:"; for (i = 0; i < n; i++) for (j = 0; j < m; j++) cin >> Matr2[i][j]; cout << "Matr2 \n"; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) cout << Matr2[i][j] << "\t"; cout << endl; } system("pause"); return 0; }
Если тебе надо больше двух, сначала проси юзера ввести необходимое кол-во матриц, а потом циклом перебирай и создавай оставляя так же просьбу с вводом значения матрицы. Сорри, если что-то не так понял, я Эльфийский не знаю.
нечетные строки массива 1 и четные массива 2 должны занестись в массив 3 --- Сообщение объединено с предыдущим 25 ноя 2019 Спасибо за ответ! И да , перевел с Эльфийского на "ЛЮДСКОЙ" язык !
#include <iostream> #include <locale> #include <iomanip> using namespace std; int main() { setlocale(LC_CTYPE, "Russian"); short *FirstMatrix, *SecondMatrix, *ResultMatrix; short Rows, Columns; // initialization cout << "Введите кол-во строк в матрице: "; cin >> Rows; cout << "Введите кол-во столбцов в матрице: "; cin >> Columns; FirstMatrix = new short[Rows * Columns]; SecondMatrix = new short[Rows * Columns]; ResultMatrix = new short[Rows * Columns]; srand((unsigned)time(NULL)); // first matrix cout << endl << "First Matrix" << endl; for (short i = 0; i < Rows; i++) { for (short j = 0; j < Columns; j++) { *(FirstMatrix + i * Columns + j) = rand() % 21 - 10; cout << setw(3) << *(FirstMatrix + i * Columns + j) << " "; } cout << endl; } //second matrix cout << endl << "Second Matrix" << endl; for (short i = 0; i < Rows; i++) { for (short j = 0; j < Columns; j++) { *(SecondMatrix + i * Columns + j) = rand() % 21 - 10; cout << setw(3) << *(SecondMatrix + i * Columns + j) << " "; } cout << endl; } // Fill ResultMatrix for (short i = 0; i < Rows; i += 2) { for (short j = 0; j < Columns; j++) { *(ResultMatrix + i * Columns + j) = *(FirstMatrix + i * Columns + j); } } for (short i = 1; i < Rows; i += 2) { for (short j = 0; j < Columns; j++) { *(ResultMatrix + i * Columns + j) = *(SecondMatrix + i * Columns + j); } } // Result cout << "Result: " << endl; for (short i = 0; i < Rows; i++) { for (short j = 0; j < Columns; j++) { cout << setw(3) << *(ResultMatrix + i * Columns + j) << " "; } cout << endl; } // del matrixs Освобождение динамической памяти delete[] FirstMatrix; delete[] SecondMatrix; delete[] ResultMatrix; } Код #include <iostream> #include <locale> #include <iomanip> using namespace std; int main() { setlocale(LC_CTYPE, "Russian"); short *FirstMatrix, *SecondMatrix, *ResultMatrix; short Rows, Columns; // initialization cout << "Введите кол-во строк в матрице: "; cin >> Rows; cout << "Введите кол-во столбцов в матрице: "; cin >> Columns; FirstMatrix = new short[Rows * Columns]; SecondMatrix = new short[Rows * Columns]; ResultMatrix = new short[Rows * Columns]; srand((unsigned)time(NULL)); // first matrix cout << endl << "First Matrix" << endl; for (short i = 0; i < Rows; i++) { for (short j = 0; j < Columns; j++) { *(FirstMatrix + i * Columns + j) = rand() % 21 - 10; cout << setw(3) << *(FirstMatrix + i * Columns + j) << " "; } cout << endl; } //second matrix cout << endl << "Second Matrix" << endl; for (short i = 0; i < Rows; i++) { for (short j = 0; j < Columns; j++) { *(SecondMatrix + i * Columns + j) = rand() % 21 - 10; cout << setw(3) << *(SecondMatrix + i * Columns + j) << " "; } cout << endl; } // Fill ResultMatrix for (short i = 0; i < Rows; i += 2) { for (short j = 0; j < Columns; j++) { *(ResultMatrix + i * Columns + j) = *(FirstMatrix + i * Columns + j); } } for (short i = 1; i < Rows; i += 2) { for (short j = 0; j < Columns; j++) { *(ResultMatrix + i * Columns + j) = *(SecondMatrix + i * Columns + j); } } // Result cout << "Result: " << endl; for (short i = 0; i < Rows; i++) { for (short j = 0; j < Columns; j++) { cout << setw(3) << *(ResultMatrix + i * Columns + j) << " "; } cout << endl; } // del matrixs Освобождение динамической памяти delete[] FirstMatrix; delete[] SecondMatrix; delete[] ResultMatrix; }