答案 0 :(得分:2)
for(int j = 0; j< r; j ++)有什么作用?你正在计算矩阵[j,col2] *矩阵[j,col3] * r次
int sum_totalcol2Xcol3 = 0;
for (int row = 0; row < r; row++)
{
sum_totalcol2Xcol3 += matrix[row, col2] * matrix[row, col3];
}
Console.WriteLine("Total is :" + sum_totalcol2Xcol3 );
或
{{1}}
答案 1 :(得分:1)
int product_col2Xcol3 = 0;
int sum_totalcol2Xcol3 = 0;
//Calculations of the SUM(Product) of col2 and col3
for (int row = 0; row < number_of_rows; row++)
{
product_col2Xcol3 = matrix[row, col2] * matrix[row, col3];
sum_totalcol2Xcol3 = sum_totalcol2Xcol3 + product_col2Xcol3 ;
}
Console.WriteLine("Total is :" + sum_totalcol2Xcol3 );
答案 2 :(得分:1)
int[,] matrix={
{1, 2, 3, 4},
{1, 2, 3, 4},
{1, 2, 3, 4},
{1, 2, 3, 4}
};
int product_col2Xcol3 = 0;
int sum_totalcol2Xcol3 = 0;
// if you precisely want the column 1 and 2 of each row then do as below:
for (int row = 0; row <matrix.GetLength(0); row++)
{
product_col2Xcol3 = matrix[row, 1] * matrix[row, 2];
sum_totalcol2Xcol3 += product_col2Xcol3;
}
Console.WriteLine("Total is :" + sum_totalcol2Xcol3);