Lab13_T1
unknown
c_cpp
3 years ago
1.2 kB
6
Indexable
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
template <class Type>
void InitMatrix(vector< vector<Type> > (&matrix))
{
cout << "SOSI HUI";
srand(time(0));
int n = matrix.size();
int k = n - 1;
int array[n];
for(int i = 0; i < n; i++)
{
array[i] = (rand() % 100) / 10;
}
for (int i = 0; i < n; i++, k--)
{
for (int j = 0; i < n; j++)
{
cout << i << " " << j;
matrix[i][n - j - 1] = array[k];
}
}
}
template <class Type>
ostream &operator<<(ostream &stream, vector< vector<Type> > (&a))
{
int n = a.size();
for (int i = 0; i < n; i++)
{
for (int j = 0; i < n; j++) {
stream << a[i][j] << " ";
}
stream << endl;
}
return stream;
}
int main()
{
int n;
cout << "Введите размерность квадратной матрицы" << endl;
cin >> n;
vector < vector<int> > matrix(n);
for(int i = 0; i < n; ++i)
{
matrix[i].resize(n);
}
InitMatrix(matrix);
cout << "Инициализированная матрица: " << endl;
cout << matrix << endl;
return 0;
}Editor is loading...