using System;
class Program
{
static void Main(string[] args)
{
Program myprogram = new Program();
int[,] arrayA = new int[2, 3];
int[,] arrayB = new int[3, 2]; for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3; j++)
{
arrayA[i,j] = i + j;
}
}
Console.WriteLine("以下输出矩阵arrayA结构");
myprogram.PrintArray(arrayA, 2, 3); for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 2; j++)
{
arrayB[i, j] = i + j + 10;
}
}
Console.WriteLine("以下输出矩阵arrayB结构");
myprogram.PrintArray(arrayB,3,2); Console.WriteLine("将矩阵A和B相乘的结果如下:");
myprogram.DMartix(arrayA, arrayB); Console.ReadLine();
}
void PrintArray(int[,] intArray, int row,int column)
{
for (int i = 0; i < row; i++)
{
Console.WriteLine("\n");
for (int j = 0; j < column; j++)
{
Console.WriteLine(intArray[i,j]+"\t");
}
Console.WriteLine("\n");
}
}
void DMartix(int[,] arrayA, int[,] arrayB)
{
int[,] resultArray = new int[2, 2];
int result = 0;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
result = 0;
for (int k = 0; i < 3; k++)
result = result + arrayA[i,k] * arrayB[k,j];
resultArray[i, j] = result;
} }
PrintArray(resultArray, 2, 2);
}
}
class Program
{
static void Main(string[] args)
{
Program myprogram = new Program();
int[,] arrayA = new int[2, 3];
int[,] arrayB = new int[3, 2]; for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3; j++)
{
arrayA[i,j] = i + j;
}
}
Console.WriteLine("以下输出矩阵arrayA结构");
myprogram.PrintArray(arrayA, 2, 3); for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 2; j++)
{
arrayB[i, j] = i + j + 10;
}
}
Console.WriteLine("以下输出矩阵arrayB结构");
myprogram.PrintArray(arrayB,3,2); Console.WriteLine("将矩阵A和B相乘的结果如下:");
myprogram.DMartix(arrayA, arrayB); Console.ReadLine();
}
void PrintArray(int[,] intArray, int row,int column)
{
for (int i = 0; i < row; i++)
{
Console.WriteLine("\n");
for (int j = 0; j < column; j++)
{
Console.WriteLine(intArray[i,j]+"\t");
}
Console.WriteLine("\n");
}
}
void DMartix(int[,] arrayA, int[,] arrayB)
{
int[,] resultArray = new int[2, 2];
int result = 0;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
result = 0;
for (int k = 0; i < 3; k++)
result = result + arrayA[i,k] * arrayB[k,j];
resultArray[i, j] = result;
} }
PrintArray(resultArray, 2, 2);
}
}
解决方案 »
- 请教如何判断字符串中是否包含某个字符?如"adfas=dfdsa"是否包含=号
- 如何修改光标为自定义图案?(注:不是鼠标箭头,而是文本框中闪烁的光标)
- 把PictureBox控件中的内容全部打印出来的方法?
- C#怎么做类是C++指针对象的比较?
- 如何在WinForm窗体中手动引发一个按钮的Click事件?
- 关于TFS的使用-服务器上可以不装vs08直接用TFS么
- 关于网页内容的文字抓取
- 趣味字符串题!
- 关于窗口与窗口的消息(WinForm)
- 噢,请问cd-key在vs.net beta2光盘的什么地方啊(别说安装时有)
- Delphi 中的 HDC 类型,在C#里面对应是什么类型??
- TreeView提交后怎样防止刷新,百分相送!请高手帮忙!
result = result + arrayA[i,k] * arrayB[k,j];
这句写错了,k写成i了
for (int k = 0; k < 3; k++)