我需要在multiplyMatrixByConstant方法中使用矩阵数组,但我不确定如何使用



我收到一个multiplyMatrixByConstant();的错误,它说";没有给出与所需的形式参数"相对应的自变量;我不确定要包括什么来允许我在multiplyMatrixByConstant();方法中使用矩阵阵列

public class Program
{
public static void Main()
{
Console.WriteLine("              ----------Welcome to the Matrix Program----------");
Console.WriteLine("Please select one of the following options:");
Console.WriteLine("1: The Random Matrix");
Console.WriteLine("2: The Transpose Matrix");
Console.WriteLine("3: Multiplying a Matrix by a Constant");
Console.WriteLine("4: Multiplying Two Matrices");
Console.Write("Your choice is: ");
string choice = Console.ReadLine();
if (choice == "1")
{
generateMatrix();
}
else if (choice == "2")
{
generateTranspose();
}
else if (choice == "3")
{
multiplyMatrixByConstant();
}
}
static int[, ] generateMatrix()
{
Console.Write("Enter the number of columns: ");
int c = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the number of rows: ");
int r = Convert.ToInt32(Console.ReadLine());
int[, ] matrix = new int[c, r];
Random rnd = new Random();
Console.WriteLine("The Matrix is: ");
for (int i = 0; i < c; i++)
{
for (int x = 0; x < r; x++)
{
matrix[i, x] = rnd.Next(0, 10);
}
}
for (int i = 0; i < c; i++)
{
for (int x = 0; x < r; x++)
{
Console.Write(matrix[i, x] + " ");
}
Console.WriteLine(" ");
}
return (matrix);
}
static void generateTranspose()
{
Console.Write("Enter the number of columns: ");
int c = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the number of rows: ");
int r = Convert.ToInt32(Console.ReadLine());
int[, ] matrix = new int[c, r];
Random rnd = new Random();
for (int i = 0; i < c; i++)
{
for (int x = 0; x < r; x++)
{
matrix[i, x] = rnd.Next(0, 10);
}
}
for (int i = 0; i < c; i++)
{
for (int x = 0; x < r; x++)
{
Console.Write(matrix[i, x] + " ");
}
Console.WriteLine(" ");
}
Console.WriteLine("The Transpose is:");
int[, ] transpose = new int[r, c];
for (int i = 0; i < c; i++)
{
for (int x = 0; x < r; x++)
{
transpose[x, i] = matrix[i, x];
}
}
for (int i = 0; i < r; i++)
{
for (int x = 0; x < c; x++)
{
Console.Write(transpose[i, x] + " ");
}
Console.WriteLine(" ");
}
}
static void multiplyMatrixByConstant(int[, ] matrix, int c, int r)
{
generateMatrix();
Console.Write(" Enter a Constant to Multiply the Matrix by: ");
int constant = Convert.ToInt32(Console.ReadLine());
int[, ] result = new int[c, r];
for (int i = 0; i < c; i++)
{
for (int x = 0; x < r; x++)
{
result[i, x] = matrix[i, x] * constant;
}
}
for (int i = 0; i < c; i++)
{
for (int x = 0; x < r; x++)
{
Console.Write(result[i, x] + " ");
}
Console.WriteLine(" ");
}
}
}

您需要收入参数(int[,]matrix,int c和int r(。

最新更新