Advertisement
Ansaid

Транспонирование матрицы

May 29th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <time.h>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     setlocale(LC_ALL, "Russian");
  12.     srand(time(NULL));
  13.     int stroka, stolbik;
  14.     cout << "Введите кол-во строчек матрицы: "; // ввод размерности
  15.     cin >> stroka;
  16.     cout << "Введите кол-во столбиков матрицы: "; // ввод размерности
  17.     cin >> stolbik;
  18.  
  19.     vector <vector <double>> arr(stroka, vector <double>(stolbik));   // создает двумерный вектор размера SIZE
  20.     vector <vector <double>> trans(stolbik, vector <double>(stroka)); // создает двумерный вектор размера SIZE
  21.  
  22.     for (int i = 0; i < stroka; i++) // присванивание значений матрице
  23.     {
  24.         for (int j = 0; j < stolbik; j++)
  25.         {
  26.             arr[i][j] = rand() % 10;
  27.         }
  28.     }
  29.  
  30.     for (int i = 0; i < stroka; i++) // вывод матрицы
  31.     {
  32.         for (int j = 0; j < stolbik; j++)
  33.         {
  34.             cout << arr[i][j] << "\t";
  35.         }
  36.         cout << endl;
  37.     }
  38.  
  39.     for (int i = 0; i < stroka ; i++) // транспонирование
  40.     {
  41.         for (int j = 0; j < stolbik; j++)
  42.         {
  43.             trans[j][i] = arr[i][j];
  44.         }
  45.         cout << endl;
  46.     }
  47.  
  48.     /*for (int i = 0; i < stroka; i++)
  49.         arr[i].clear();
  50.     arr.clear();*/
  51.  
  52.     for (int i = 0; i < stolbik; i++) // вывод транспонированной матрицы
  53.     {
  54.         for (int j = 0; j < stroka; j++)
  55.         {
  56.             cout << trans[i][j] << "\t";
  57.         }
  58.         cout << endl;
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement