using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace exe_3
{
class matrix
{
public int row;
public int col;
public int[,] mar; //mar为二维数组名
public matrix(int row, int col, int[,] mar)
{
this.row = row;
this.col = col;
mar = new int[this.row, this.col];
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
this.mar[i, j] = mar[i, j]; }
}
}
public static matrix operator +(matrix mar1, matrix mar2) //mar1,mar2为矩阵的对象
{
//声明一个临时的矩阵存放两个矩阵相加之和
matrix temp = new matrix(mar1.mar.GetUpperBound(0) + 1, mar1.mar.GetUpperBound(1) + 1, new int[mar1.mar.GetUpperBound(0) + 1, mar1.mar.GetUpperBound(1) + 1]); for (int i = 0; i <= mar1.mar.GetUpperBound(0); i++)
{
for (int j = 0; j <= mar1.mar.GetUpperBound(1); j++)
{
temp.mar[i, j] = mar1.mar[i, j] + mar2.mar[i, j];
} } return (temp);
} }
}
////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace exe_3
{
class Program
{
static void Main(string[] args)
{ //int[,] mar1 = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } };
//int[,] mar2 = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } };
matrix mar3 = new matrix(2, 3, new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } });
matrix mar4 = new matrix(2, 3, new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } }); //int row = int.Parse(Console.ReadLine());
//int col = int.Parse(Console.ReadLine());
//int[,] mar1 = new int[2,3]{{1,2,3},{4,5,6}};
//int[,] mar2 = new int[2,3]{{1,2,3},{4,5,6}};
//mar.add(mar1, mar2);
matrix m = mar3 + mar4;
Console.Read(); }
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace exe_3
{
class matrix
{
public int row;
public int col;
public int[,] mar; //mar为二维数组名
public matrix(int row, int col, int[,] mar)
{
this.row = row;
this.col = col;
mar = new int[this.row, this.col];
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
this.mar[i, j] = mar[i, j]; }
}
}
public static matrix operator +(matrix mar1, matrix mar2) //mar1,mar2为矩阵的对象
{
//声明一个临时的矩阵存放两个矩阵相加之和
matrix temp = new matrix(mar1.mar.GetUpperBound(0) + 1, mar1.mar.GetUpperBound(1) + 1, new int[mar1.mar.GetUpperBound(0) + 1, mar1.mar.GetUpperBound(1) + 1]); for (int i = 0; i <= mar1.mar.GetUpperBound(0); i++)
{
for (int j = 0; j <= mar1.mar.GetUpperBound(1); j++)
{
temp.mar[i, j] = mar1.mar[i, j] + mar2.mar[i, j];
} } return (temp);
} }
}
////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace exe_3
{
class Program
{
static void Main(string[] args)
{ //int[,] mar1 = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } };
//int[,] mar2 = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } };
matrix mar3 = new matrix(2, 3, new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } });
matrix mar4 = new matrix(2, 3, new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } }); //int row = int.Parse(Console.ReadLine());
//int col = int.Parse(Console.ReadLine());
//int[,] mar1 = new int[2,3]{{1,2,3},{4,5,6}};
//int[,] mar2 = new int[2,3]{{1,2,3},{4,5,6}};
//mar.add(mar1, mar2);
matrix m = mar3 + mar4;
Console.Read(); }
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货