我可以在一個多維數組中總結2個值並使用控制檯應用程序進行打印。下面的代碼打印每個多維數組的2個和。但是我需要的是,打印2個多維數組的總和。我已經清理了代碼,使其不那麼複雜。2個多維數組的總和
int[,] a = new int[2, 2];
int[,] b = new int[2, 2];
int[,] c = new int[2, 2];
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 1; j++)
{
Console.Write("Please enter {0}. Mark of First lesson", i + 1, j + 1);
a[i, j] = Int32.Parse(Console.ReadLine());
}
}
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 1; j++)
{
Console.Write("Please enter {0}. Mark of Second lesson", i + 1, j + 1);
b[i, j] = Int32.Parse(Console.ReadLine());
}
}
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 1; j++)
{
c[i, j] = a[i, j] + b[i, j];
Console.WriteLine("{0}."+c[i, j],i+1+"The sum of 2 marks is:",j+1);
}
}
Console.ReadKey();
哦,我的天啊,你太棒了。你剛剛救了我:)。非常感謝! –