using System;
namespace 加减乘除
{
class Class1
{
private static int [,]add(int [,]array1,int [,]array2)
{
int [,]array = new int[3,3];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
array[i,j] = array1 [i,j] + array2[i,j];
}
}
return array;
}
private static int [,]sub(int [,]array1,int [,]array2)
{
int [,]array = new int[3,3];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
array[i,j] = array1 [i,j] - array2[i,j];
}
}
return array;
}
private static int [,]mup(int [,]array1,int [,]array2)
{
int [,]array = new int[3,3];
for (int i = 0; i < 3; i++)
{
int j;
for ( j = 0; j < 3; j++)
{
array[i,j] = 0;
for (int k = 0; k < 3; k++)
array[i,j] += array1[i,k]*array2[k,j];
}
}
return array;
}
private static int [,]Input(int [,] array1)
{
int [,]array = new int[3,3];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
array[i,j] = Convert.ToInt32(Console.ReadLine());
}
}
return array;
}
private static void Output(int [,]array1)
{
for (int i = 0; i < 3; i++)
{
int j;
for ( j = 0; j < 3; j++)
{
Console.Write("{0,4}",array1[i,j]);
}
Console.WriteLine();
}
}
public static void Main(string[] args)
{
int [,]a = new int[3,3];
int [,]b = new int[3,3];
int [,]c = new int[3,3];
int [,]d = new int[3,3];
int [,]e = new int[3,3];
Console.WriteLine("请输入第一个距阵:");
a = Input(a);
Console.WriteLine("请输入第2个距阵:");
b = Input(b);
Console.WriteLine("第一个数组为");
Output(a);
Console.WriteLine("第2个数组为");
Output(b);
Console.WriteLine("进行加法运算:");
c = add(a,b);
Output(c);
Console.WriteLine("进行减法运算:");
d = sub(a,b);
Output(d);
Console.WriteLine("进行乘法运算:");
e = mup(a,b);
Output(e);
Console.ReadLine();
}
}
}
程序还有很多需要改进的地方 比如想计算任意2个数组的加减乘 等等 读者想做加减乘中的一项 等