Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.IO;
- using System;
- class Matrix
- {
- public Matrix(int rows, int cols)
- {
- data = new double[rows, cols];
- }
- public Matrix(double[,] d)
- {
- data = new double[d.GetLength(0), d.GetLength(1)];
- for (int i = 0; i < data.GetLength(0); i++)
- for (int j = 0; j < data.GetLength(1); j++)
- data[i, j] = d[i, j];
- }
- public Matrix(Matrix m)
- {
- data = new double[m.data.GetLength(0), m.data.GetLength(1)];
- for (int i = 0; i < data.GetLength(0); i++)
- for (int j = 0; j < data.GetLength(1); j++)
- data[i, j] = m.data[i, j];
- }
- public double this[int r, int c]
- {
- get
- {
- return data[r, c];
- }
- set
- {
- data[r, c] = value;
- }
- }
- public static Matrix operator+(Matrix lhs, Matrix rhs)
- {
- //Сделать проверку на одинаковость размеров
- double[,] d = new double[lhs.data.GetLength(0), lhs.data.GetLength(1)];
- for (int i = 0; i < d.GetLength(0); i++)
- for (int j = 0; j < d.GetLength(1); j++)
- d[i, j] = lhs[i, j] + rhs[i, j];
- return new Matrix(d);
- }
- public double[,] data;
- }
- class Program
- {
- static void Main()
- {
- Matrix a = new Matrix(1, 1);
- a[0, 0] = 5;
- Matrix b = new Matrix(a);
- b[0, 0] = 10;
- Matrix c = a + b;
- Console.WriteLine(c[0, 0]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement