0
我无法在任务中获得矩阵的乘积,以便在多个实例中运行该矩阵乘积 。我认为这项任务并没有正确地进行乘法运算并调用几个0。如何在任务中进行矩阵乘法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _010029428_Multiplicacion
{
class Program
{
static void Main(string[] args)
{
int i, j, m, n;
Random rnd = new Random((int)DateTime.Now.Ticks & 0x000fff);
Console.WriteLine("Ingrese el numero de renglones y columnas: ");
m = Convert.ToInt32(Console.ReadLine());
n = Convert.ToInt32(Console.ReadLine());
int[,] a = new int[m, n];
Console.WriteLine("first Matrix");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
a[i, j] = rnd.Next(1, 4);
}
}
Console.WriteLine("First matrix is: ");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
Console.Write(a[i, j] + "\t");
}
Console.WriteLine();
}
int[,] b = new int[m, n];
Console.WriteLine("Second Matrix: ");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
b[i, j] = rnd.Next(1, 4);
}
}
Console.WriteLine("The second matrix is:");
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
Console.Write(b[i, j] + "\t");
}
Console.WriteLine();
}
Console.WriteLine("The result is :");
int[,] c = new int[m, n];
var multiplicacion = new Task(() =>
{
for (j = 0; j < n; j++)
{
c[i, j] = 0;
for (int k = 0; k < n; k++)
{
c[i, j] += a[i, k] * b[k, j];
}
}
});
for (i = 0; i < m; i++)
{
multiplicacion.Start();
}
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
Console.Write(c[i, j] + "\t");
}
Console.WriteLine();
}
}
}
}
的代码使用multiplicacion.start()异步运行它 不知道这个问题可能是什么
非常感谢你,我不明白几个任务的主要问题。 –