Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- int n, i, j;
- // Вывод двумерного массива
- void output_an_array(int **array) {
- for (i = 0; i < n; i++) {
- for (j = 0; j < n; j++)
- cout << array[i][j] << " ";
- cout << endl;
- }
- cout << endl;
- }
- // Копирование данных из массива "a" в массив "b"
- void copy_array(int **a, int **b) {
- for (i = 0; i < n; i++)
- for (j = 0; j < n; j++)
- b[i][j] = a[i][j];
- }
- // Изменение столбцов по порядку со строками в обратном порядке
- int **columns_to_rows(int **a) {
- int **sub = new int *[n];
- for (i = 0; i < n; i++) {
- sub[i] = new int[n];
- }
- copy_array(a, sub);
- for (i = 0; i < n; i++)
- for (j = 0; j < n; j++)
- sub[j][i] = a[n - i - 1][j];
- return sub;
- }
- int main(int argc, char *argv[]) {
- srand(time(0));
- cout << "Enter the size of the array" << endl;
- cin >> n;
- cout << endl;
- int **m = new int *[n];
- int **mul = new int *[n];
- int *v = new int[n];
- for (i = 0; i < n; i++) {
- m[i] = new int[n];
- mul[i] = new int[n];
- }
- for (i = 0; i < n; i++)
- for (j = 0; j < n; j++)
- m[i][j] = rand() % 90 + 10;
- cout << "Output of the initial array:" << endl;
- output_an_array(m);
- // Задание "а"
- for (i = 0; i < n; i++)
- v[i] = m[i][i] * m[i][i];
- cout << "Output of the \"Vk\" array:" << endl;
- for (i = 0; i < n; i++)
- cout << v[i] << " ";
- cout << endl;
- // Задание "б"
- cout << endl << "Array where columns are replaced with rows in reverse order:" << endl;
- output_an_array(columns_to_rows(m));
- // Задание "в"
- cout << "M*V:" << endl;
- for (i = 0; i < n; i++)
- for (j = 0; j < n; j++)
- mul[i][j] = m[i][j] * v[j];
- output_an_array(mul);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement